-
Notifications
You must be signed in to change notification settings - Fork 70
Add short circuiting functions of elem
, notElem
, find
, findMap
, scanl
, and scanr
#189
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 short circuiting functions of elem
, notElem
, find
, findMap
, scanl
, and scanr
#189
Conversation
Can I get a review on this? |
assert $ (A.find (_ /= 1) [1, 2, 1]) == Just 2 | ||
assert $ (A.find (_ == 3) [1, 2, 1]) == Nothing | ||
|
||
log "findMap should return the mapping of the first element that satisfies the given 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 it would be good to also add a test case for an array where there is more than one element which satisfies the predicate here.
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 in latest commits
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.
Sorry, I should have been clearer: I think we should have a test which rules out the possibility that our findMap
actually returns the last match.
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've updated the tests to account for that.
@@ -237,6 +253,14 @@ testArray = do | |||
assert $ A.modifyAtIndices [0, 2, 8] not [true, true, true, true] == | |||
[false, true, false, true] | |||
|
|||
log "scanl should return an array that stores the accumulated value at each step" | |||
assert $ A.scanl (+) 0 [1,2,3] == [1, 3, 6] |
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.
Can we test that these agree with the Foldable versions please? It's probably not necessary to compare with the Foldable versions for the other functions, but this one differs from Haskell and so there's more than one "sensible" option for how to implement it, so I think it's worth being a little bit more careful/deliberate in the tests.
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.
Could you clarify what you mean by this? The tests I used were taken from the scanl
docs and scanr
docs
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.
Rereading this again, I think you mean this:
assert $ A.scanl (+) 0 [1,2,3] == scanl (+) 0 [1,2,3]
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.
Yeah, exactly.
src/Data/Array.purs
Outdated
scanl :: forall a b. (b -> a -> b) -> b -> Array a -> Array b | ||
scanl = scanlImpl | ||
|
||
foreign import scanlImpl :: forall a b. (b -> a -> b) -> b -> Array a -> Array b |
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.
Since the FFI implementation is ready to use as-is, we can just import it as scanl
straight away; I don't think there's any need to alias it.
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 in latest commits
I believe I've addressed all your comments. |
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.
LGTM, thanks
See #173 (comment)