feat(stream-helpers): add take, takeWhile, and takeUntil helpers #136
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
Adds three new stream transformer helpers for limiting/filtering streams:
take(n): Yields the firstnvalues, then closes with the nth value as the close value.takeWhile(predicate): Yields values while the predicate returns true. Closes immediately when the predicate fails (does not include the failing value).takeUntil(predicate): Yields values until the predicate returns true. Closes with the matching value (includes it as the close value).All helpers use curried style for pipe compatibility.
Use Cases
take- Limit stream to first N valuestakeWhile- Take values while condition holdstakeUntil- Iterate until terminal condition (wizard validation pattern)Key Difference:
takeWhilevstakeUntiltakeWhileundefinedtakeUntilThe
takeUntilpattern is particularly useful for validation flows where the matching value (e.g.,{status: "valid", data: ...}) carries meaningful data you want to use.Notes
take(n)(stream)streamOf()for simpler, synchronous test casestakeWhileno longer drains the stream when predicate fails