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

Change type signatures of Data.List.NonEmpty.intersect and Data.List.NonEmpty.intersectBy to return a List instead of a NonEmptyList #217

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Notable changes to this project are documented in this file. The format is based

Breaking changes:

- Changed type signatures of `Data.List.NonEmpty.intersect` and `Data.List.NonEmpty.intersectBy` to return a `List` instead of a `NonEmptyList` (#217)

New features:

Bugfixes:
Expand Down
8 changes: 4 additions & 4 deletions src/Data/List/NonEmpty.purs
Original file line number Diff line number Diff line change
Expand Up @@ -284,11 +284,11 @@ union = wrappedOperation2 "union" L.union
unionBy :: forall a. (a -> a -> Boolean) -> NonEmptyList a -> NonEmptyList a -> NonEmptyList a
unionBy = wrappedOperation2 "unionBy" <<< L.unionBy

intersect :: forall a. Eq a => NonEmptyList a -> NonEmptyList a -> NonEmptyList a
intersect = wrappedOperation2 "intersect" L.intersect
intersect :: forall a. Eq a => NonEmptyList a -> NonEmptyList a -> L.List a
intersect = intersectBy eq

intersectBy :: forall a. (a -> a -> Boolean) -> NonEmptyList a -> NonEmptyList a -> NonEmptyList a
intersectBy = wrappedOperation2 "intersectBy" <<< L.intersectBy
intersectBy :: forall a. (a -> a -> Boolean) -> NonEmptyList a -> NonEmptyList a -> L.List a
intersectBy eq xs ys = L.intersectBy eq (toList xs) (toList ys)

zipWith :: forall a b c. (a -> b -> c) -> NonEmptyList a -> NonEmptyList b -> NonEmptyList c
zipWith f (NonEmptyList (x :| xs)) (NonEmptyList (y :| ys)) =
Expand Down
7 changes: 5 additions & 2 deletions test/Test/Data/List/NonEmpty.purs
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,13 @@ testNonEmptyList = do
assert $ NEL.unionBy (\_ y -> y < 5) (nel 1 [2, 3]) (nel 2 [3, 4, 5, 6]) == nel 1 [2, 3, 5, 6]

log "intersect should return the intersection of two lists"
assert $ NEL.intersect (nel 1 [2, 3, 4, 3, 2, 1]) (nel 1 [1, 2, 3]) == nel 1 [2, 3, 3, 2, 1]
assert $ NEL.intersect (nel 1 [2, 3, 4, 3, 2, 1]) (nel 1 [1, 2, 3]) == L.fromFoldable [1, 2, 3, 3, 2, 1]

log "intersect should return empty list when lists do not intersect"
assert $ NEL.intersect (nel 1 [2, 3, 4, 3, 2, 1]) (nel 5 [6, 7, 8]) == L.Nil

log "intersectBy should return the intersection of two lists using the specified equivalence relation"
assert $ NEL.intersectBy (\x y -> (x * 2) == y) (nel 1 [2, 3]) (nel 2 [6]) == nel 1 [3]
assert $ NEL.intersectBy (\x y -> (x * 2) == y) (nel 1 [2, 3]) (nel 2 [6]) == L.fromFoldable [1, 3]

log "zipWith should use the specified function to zip two lists together"
assert $ NEL.zipWith (\x y -> nel (show x) [y]) (nel 1 [2, 3]) (nel "a" ["b", "c"]) == nel (nel "1" ["a"]) [nel "2" ["b"], nel "3" ["c"]]
Expand Down
Loading