-
Notifications
You must be signed in to change notification settings - Fork 69
Add missing members to Data.Array.NonEmpty #201
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
Add missing members to Data.Array.NonEmpty #201
Conversation
I think we should export monomorphic versions of the fold* functions in both this module and in Data.Array, see #173. |
Data.Array.NonEmpty does not have |
I've updated |
Nevermind. This specific PR doesn't include those members in its exports because it was based on a previous branch. Once I merged it with |
@@ -106,6 +114,15 @@ testNonEmptyArray = do | |||
assert $ NEA.elemLastIndex 1 (fromArray [1, 2, 1]) == Just 2 | |||
assert $ NEA.elemLastIndex 4 (fromArray [1, 2, 1]) == Nothing | |||
|
|||
log "find should return the first element for which a predicate returns true in an array" | |||
assert $ NEA.find (_ /= 1) (fromArray [1, 2, 1]) == Just 2 | |||
assert $ NEA.find (_ == 3) (fromArray [1, 2, 1]) == Nothing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should there be another test here to verify that the first element is returned when two or more elements would satisfy the predicate?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so. We could also ensure that findIndex actually returns the index of the first match by changing the _ /= 1
predicate to _ == 1
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
Shouldn’t we rather remove the re-exports? That’s quite inconsistent with purescript/purescript-nonempty#42, where we deprecated the monomorphic Data.NonEmpty.foldl1, otherwise. |
I suppose it is but if we want these to be consistent then we should reintroduce Data.NonEmpty.foldl1. Removing these re-exports from Data.Array is much too breaking to be worthy of consideration in my mind. |
I think that was deprecated because, while the |
I'll open an PR that re-adds the monomorphic |
We added a few functions to Data.Array in #189, #188 and #68 but forgot to export variants from Data.Array.NonEmpty.
This pull request adapts them to non empty arrays and also re-exports foldl1, foldr1, foldMap1, fold1 and intercalate (from Data.Semigroup.Foldable) so that Data.Array and Data.Array.NonEmpty have (mostly) the same interface.