0no-co / wonka

🎩 A tiny but capable push & pull stream library for TypeScript and Flow
MIT License
709 stars 29 forks source link

feat: Add an addOne argument to takeWhile #156

Closed kitten closed 1 year ago

kitten commented 1 year ago

Summary

I realised this is impossible to express without a takeUntil and share operator, but is sometimes pretty handy, e.g. to say "take values until predicate returns false, but include the ending value".

This adds an addOne?: boolean argument to takeWhile which allows the first value that fails the predicate to also be issued on the output Source rather than being omitted.

This comes in handy for GraphQL’s incremental results, e.g. to express takeWhile(result => !!result.hasNext). This is important, since the first result in GraphQL may pass !hasNext but will still contain new data. It's also, while implied in the spec, not guaranteed that the last result with hasNext: false won't carry a new result.

Set of changes