Skip to content

Should we have a specialized version of find? #143

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

Closed
paulyoung opened this issue Jun 22, 2018 · 2 comments
Closed

Should we have a specialized version of find? #143

paulyoung opened this issue Jun 22, 2018 · 2 comments

Comments

@paulyoung
Copy link

I'm thinking this will be better because it won't continue to process the remainder of the array after finding a match.

find :: forall a. (a -> Boolean) -> Array a -> Maybe a
find p xs = findIndex p xs >>= index x
@paulyoung
Copy link
Author

@themattchan came up with this, which is even better:

find :: forall a. (a -> Boolean) -> Array a -> Maybe a
find f xs = unsafePartial $ unsafeIndex xs <$> findIndex f xs

@kl0tl
Copy link
Member

kl0tl commented Dec 17, 2020

This was done in #189.

@kl0tl kl0tl closed this as completed Dec 17, 2020
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

No branches or pull requests

2 participants