Skip to content

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

Conversation

kl0tl
Copy link
Member

@kl0tl kl0tl commented Dec 28, 2020

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.

@hdgarrood
Copy link
Contributor

I think we should export monomorphic versions of the fold* functions in both this module and in Data.Array, see #173.

@JordanMartinez
Copy link
Contributor

Data.Array.NonEmpty does not have groupAll or groupAllBy. I'm assuming we want these included there, too, correct?

@JordanMartinez
Copy link
Contributor

I've updated Data.Array and Data.Array.NonEmpty to export monomorphic versions of foldl, foldr, fold1, foldMap, and intercalate.

@JordanMartinez
Copy link
Contributor

Data.Array.NonEmpty does not have groupAll or groupAllBy. I'm assuming we want these included there, too, correct?

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 master, that was no longer the case.

@@ -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
Copy link
Contributor

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?

Copy link
Member Author

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 .

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@kl0tl
Copy link
Member Author

kl0tl commented Dec 30, 2020

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.

@hdgarrood
Copy link
Contributor

hdgarrood commented Dec 30, 2020

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.

@JordanMartinez
Copy link
Contributor

Shouldn’t we rather remove the re-exports?

I think that was deprecated because, while the NonEmpty part is monomorphic, its underlying f is still polymorphic. Here, we have a monomorphic Array or NonEmptyArray.

@JordanMartinez JordanMartinez merged commit 7d3664d into purescript:master Dec 30, 2020
@JordanMartinez
Copy link
Contributor

I'll open an PR that re-adds the monomorphic fold1 to NonEmpty

@JordanMartinez
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants