Add map and filter to persistent vector#6
Conversation
There was a problem hiding this comment.
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.
-
mapsignature(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.,IntVecholdsInt), so cross-type mapping (Int → String) isn't expressible without a different output vector type. Consistent with the library's design. -
filterpredicate takes(Ref %value-type), matching the convention used byany?andall?. Theifbranches both return owned vectors —push-back x &accwhen the predicate holds,accotherwise — so ownership is correct. -
reduceiterates in index order, andpush-backappends, so bothmapandfilterpreserve 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.
Vector was the only sequential structure (out of List, Queue, Deque, Vector) that lacked
mapandfilter. 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.