-
Notifications
You must be signed in to change notification settings - Fork 30
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
Array additions #49
Array additions #49
Conversation
1129d62
to
39c6af0
Compare
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.
Thanks! Here is some feedback from my part.
What do you think @zth?
Thanks @glennsl, these additions look quite useful. I added my comments to the discussion as well. |
b4d2003
to
889e993
Compare
I suppose this could be merged now, since neither documentation for the rest of the module or a test framework is in place yet. It could also be what initiates both. Up to you! |
If you don't mind, I think adding both in this PR would be good, so it doesn't get left behind. Would that be OK? Let me know how I can help out if needed. |
Also, a change log entry would be good as well. |
Sure. Do you have any thoughts on testing framework? Should I pull in something like |
We have a simple one already in Thank you for all your contributions so far by the way, very valuable! 👍 |
889e993
to
ffc18ee
Compare
Added documentation, tests and updated the changelog. Also fixed |
Great! Taking a look again soon. |
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.
Actually, reduce
and reduceReverse
were intentionally taken from Belt
instead of using their native counterparts because the Belt
version allows for full type inference whereas the native one does not. So that was a deliberate decision.
Just had a small comment, other than that and the reduce stuff this is good to go from my end. Thanks!
cc @cknitt if you want to have a last look as well.
If it's just for the improved argument order for better type inference, then we could simply do @send external reduce: (array<'b>, ('a, 'b) => 'a, 'a) => 'a = "reduce"
let reduce = (arr, x, f) => reduce(arr, f, x) (same for |
Indeed. Seems odd to have them reimplemented and with different names when only a reordering of the arguments is needed. Could probably also just label the argument to allow it to be moved before the callback function?
|
IIRC the Belt version actually has better performance than the native one. Anyway, just reordering the arguments like that is fine. Let's do that instead and axe the reimplementation. Side note - it's entirely possible that we'll have a way to do this directly in the binding in the future too, which would make it zero cost. Not there yet though. |
So, reorder, not label? |
Correct. |
Arguments reordered! Also reordered the type variable names for consistency. |
Yes, great work! I think it would be good to use pipe |
This adds:
make
, seems necessary to be able to create initialized arrays without imperatively pushing onto an empty array.init
, ismake
with an initializer function instead of a constant.findMap
, is surprisingly useful, to find an element in a nested array, for example ([[1, 2], [3]]->findMap(find(_, el => ...))
), or to find the first element in anarray<option<_>>
that is notNone
.keepSome
, unwraps the options in anarray<option<_>>
while discarding theNone
s.It also replaces the reimplementation of flatMap with a binding to
Array.prototype.flatMap
.This is, to begin with, just to gather some feedback on the relevance, naming and implementations, before I add documentation and tests.
TODO: