Skip to content

Add map and filter to persistent vector#6

Merged
hellerve merged 1 commit into
mainfrom
claude/vector-map-filter
Jun 9, 2026
Merged

Add map and filter to persistent vector#6
hellerve merged 1 commit into
mainfrom
claude/vector-map-filter

Conversation

@carpentry-agent

Copy link
Copy Markdown

Vector was the only sequential structure (out of List, Queue, Deque, Vector) that lacked map and filter. This adds both, following the same reduce-based pattern used by the other structures.

map applies a function to each element, building a new vector in index order via push-back.

filter keeps elements satisfying a predicate, preserving index order.

Tests cover: basic map/filter, empty collections, always-false predicate, always-true predicate.


Opened by the carpentry-org heartbeat agent (Claude). Veit has not reviewed this yet.

@carpentry-reviewer carpentry-reviewer Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Build & Tests

Build: pass (local aarch64 + CI on macOS/Ubuntu).
Tests: all 18 pass, including 5 new assertions for map and filter. The reset-memory-balance! crash at the end of the test file is pre-existing on main (unrelated to this PR).

Findings

Both implementations are clean and follow the established reduce+push-back pattern used by List, Queue, and Deque in this library.

  • map signature (Fn [%value-type] %value-type) correctly constrains the mapping function to same-type transforms. This is the right choice — the persistent vector type is monomorphic (e.g., IntVec holds Int), so cross-type mapping (Int → String) isn't expressible without a different output vector type. Consistent with the library's design.

  • filter predicate takes (Ref %value-type), matching the convention used by any? and all?. The if branches both return owned vectors — push-back x &acc when the predicate holds, acc otherwise — so ownership is correct.

  • reduce iterates in index order, and push-back appends, so both map and filter preserve index order. Verified by the test assertions checking specific indices.

  • Test coverage: basic map, map empty, basic filter, filter always-false, filter always-true. The edge cases are the right ones.

No bugs or issues found.

Verdict: merge

Fills the obvious API gap (Vector was the only sequential structure without map/filter). Code follows existing patterns, tests are solid.

@hellerve hellerve merged commit f0d8607 into main Jun 9, 2026
2 checks passed
@hellerve hellerve deleted the claude/vector-map-filter branch June 9, 2026 17:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant