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.
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