Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make groupBy stable #148

Merged
merged 1 commit into from
Sep 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Data/Array.purs
Original file line number Diff line number Diff line change
Expand Up @@ -866,8 +866,8 @@ groupBy op xs =
iter <- STAI.iterator (xs !! _)
STAI.iterate iter \x -> void do
sub <- STA.empty
STAI.pushWhile (op x) iter sub
_ <- STA.push x sub
STAI.pushWhile (op x) iter sub
grp <- STA.unsafeFreeze sub
STA.push ((unsafeCoerce :: Array ~> NonEmptyArray) grp) result
STA.unsafeFreeze result
Expand Down
3 changes: 3 additions & 0 deletions test/Test/Data/Array.purs
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,9 @@ testArray = do
log "groupBy should group consecutive equal elements into arrays based on an equivalence relation"
assert $ A.groupBy (\x y -> odd x && odd y) [1, 1, 2, 2, 3, 3] == [nea [1, 1], NEA.singleton 2, NEA.singleton 2, nea [3, 3]]

log "groupBy should be stable"
assert $ A.groupBy (\_ _ -> true) [1, 2, 3] == [nea [1, 2, 3]]

log "nub should remove duplicate elements from the list, keeping the first occurence"
assert $ A.nub [1, 2, 2, 3, 4, 1] == [1, 2, 3, 4]

Expand Down