Skip to content
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

Inclusive takeWhile #2

Open
OliverJAsh opened this issue Mar 4, 2017 · 2 comments
Open

Inclusive takeWhile #2

OliverJAsh opened this issue Mar 4, 2017 · 2 comments

Comments

@OliverJAsh
Copy link

Hi!

Do you have any plans to add an inclusive takeWhile?

An example of where this would be useful:

[1,2,3,4].takeWhile(x => x < 3)
// [ 1, 2 ]
[1,2,3,4].takeWhileInclusive(x => x < 3)
// [ 1, 2, 3 ]

Note, although it is easy to change the function in this example to achieve the same result, in my use case I do not want to execute next on the value after the last desired output.

@marcinnajder
Copy link
Owner

Hi!

Thanks for question :) I don't have any plan to add such a operator. It's because I didn't see any use case for it (but I see it can be useful). My background is .net (also Rx and Ix) and there is only takeWhile, here is the whole list of operators https://github.com/marcinnajder/powerseq/blob/master/docs/mapping.md.

But you can always add a new operatator seamlessly to powerseq without modifying source code of powerseq. Just copy a file https://github.com/marcinnajder/powerseq/blob/master/src/operators/takewhile.ts to your project, change it to takeWhileInclusive and import it from ES6/TS file. Everything should work fine. We can also consider adding it to powerseq.

Have you seen takeWhileInclusive operator in any other technology/language?

@OliverJAsh
Copy link
Author

There is precedent for this in RxJava, where takeUntil takes a function and is inclusive:

http://reactivex.io/RxJava/javadoc/rx/Observable.html#takeUntil(rx.functions.Func1)

I see there is also discussion about adding this to RxJS ReactiveX/rxjs#2420

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