Skip to content

Commit

Permalink
Fix filtering with list of lists
Browse files Browse the repository at this point in the history
Second time I've been big by the ordering of items in the append
method.
  • Loading branch information
mitchpaulus committed Dec 17, 2024
1 parent 80f8796 commit 1aa2b25
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/std.msh
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def filter ([T] (T -- bool) -- [T])
over @filter-idx nth # Get current item
dup rot # Get to item item quote
x # Execute quote
[() (@filter-accum append filter-accum!) (drop)] if
[() (@filter-accum swap append filter-accum!) (drop)] if
drop @filter-idx 1 + filter-idx! # inc index
) loop

Expand Down
3 changes: 3 additions & 0 deletions tests/filter.msh
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
[1 2 3 4 5] (3 >) filter (str) map ", " join wl

# Test filtering list of lists, this caught a bug with the order of the internal append in filter
[[1 2] [] [3 4 5]] (len 1 >) filter ((str) map ", " join) map uw
2 changes: 2 additions & 0 deletions tests/filter.msh.stdout
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
4, 5
1, 2
3, 4, 5

0 comments on commit 1aa2b25

Please sign in to comment.