feat: Add an addOne argument to takeWhile #156
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
I realised this is impossible to express without a
takeUntil
andshare
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 totakeWhile
which allows the first value that fails the predicate to also be issued on the outputSource
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 newdata
. It's also, while implied in the spec, not guaranteed that the lastresult
withhasNext: false
won't carry a new result.Set of changes
addOne
argument totakeWhile