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
Operator: takeUntil #7
Comments
An example of where this would be useful: [1,2,3,4].takeUntil(x => x >= 3)
// [ 1, 2 ]
[1,2,3,4].takeUntilInclusive(x => x >= 3)
// [ 1, 2, 3 ] I'm not sure if |
Upon investigation, it looks like |
@OliverJAsh added |
Hi @mattpodwysocki. The Would you consider adding this? |
To anyone who comes here needing this. Here's a custom implementation you can use: export const takeUntil = <T>(fn: (value: T) => boolean) => (
asyncIterable: AsyncIterable<T>,
): AsyncIterable<T> =>
Ix.AsyncIterable
.from(asyncIterable)
.map(value => {
const shouldEnd = fn(value);
return shouldEnd
? [{ value, done: false }, { value: undefined, done: true }]
: [{ value, done: false }];
})
.flatMap(iterable => Ix.AsyncIterable.from(iterable))
// We know `value` has type `T` because of the `takeWhile` guard
// https://github.com/ReactiveX/IxJS/issues/44
.takeWhile(x => !x.done)
.map(({ value }) => value as T); |
Similar feature request for RxJS, which seems to have a good amount of support: ReactiveX/rxjs#2420. If I sent a PR for this, would it be reviewed and potentially accepted? Related: https://github.com/martinsik/rxjs-plus#takewhileinclusive |
@OliverJAsh yes, definitely! @mattpodwysocki might have more time than me, I'm pretty slammed till the end of the month, but we should be able to work it in. |
Hi!
Are there plans to add a
takeUntil
operator to this library?If so, I was wondering if we would have inclusive (take until and including) and exclusive versions (take until and excluding the first falsy predicate).
The text was updated successfully, but these errors were encountered: