-
Notifications
You must be signed in to change notification settings - Fork 35
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
Question: Why do functions like iterable/first
yield?
#59
Comments
I admit that this is slightly weird, but it's also slightly more powerful in terms of composition... This was also one of the most difficult choices I made for the library. Say they actually returned the result instead. What would In comparison, check out this section in the README: https://github.com/jussi-kalliokoski/trine#maybe . Iterables actually implement the maybe contract (they can be mapped even if they're empty), which allows you to push error/null checks to the edges instead of doing them on every step. I think for |
Vanilla JS returns
This definitely makes sense. And thanks for the link – this cleared things out a little bit. I’m quite new to this iterators thing. Now I know I have to apply I must admit I was a bit lost, I needed quick results – so I ended up with a dirty Perhaps it would make sense to show [1,2,3]::count().next() // returns 3 – instead of: [1,2,3]::count() // yields 3 |
Hi,
I’ve just noticed that
trine/iterable/first
,trine/iterable/find
and others – functions which take an iterable and spit out a single value – don’t return the resulting value but yield it.I supposed
[0, 0, 4]::find(isTruthy)
would return4
– just as[0, 0, 4].find(Boolean)
returns4
and not[4]
. Out of curiosity – what’s the reason for that?I’ve even written a library which builds upon what I supposed: iterable-some 😃.
The text was updated successfully, but these errors were encountered: