Merged
Conversation
- Implement flatMap/mergeMap for concurrent inner stream handling - Implement switchMap for latest-only stream switching with cancellation - Implement exhaustMap to prevent overlapping operations - Add comprehensive test suites validating monad laws for flatMap - Update operators index to export new operators
- Document flatMap, switchMap, and exhaustMap operators with comparisons - Add decision guide for choosing between operator patterns - Include visual diagrams and practical use case examples - Update sidebar navigation with new operator pages
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
Add monad structure to Stream with
flatMap,switchMap, andexhaustMapoperators for async stream composition.Changes
New Operators
flatMap(alias:mergeMap)switchMapexhaustMapFiles Added
src/operators/flat-map.ts- flatMap/mergeMap implementationsrc/operators/switch-map.ts- switchMap implementationsrc/operators/exhaust-map.ts- exhaustMap implementationsrc/operators/flat-map.spec.ts- flatMap tests (including monad laws)src/operators/switch-map.spec.ts- switchMap testssrc/operators/exhaust-map.spec.ts- exhaustMap testsFiles Modified
src/operators/index.ts- Added exports for new operatorsImplementation Details
flatMap (mergeMap)
switchMap
exhaustMap
Monad Laws Verification
Tests verify that
flatMapsatisfies the three monad laws:pure(a).flatMap(f) === f(a)m.flatMap(pure) === mm.flatMap(f).flatMap(g) === m.flatMap(x => f(x).flatMap(g))Test Coverage
Test Scenarios
Breaking Changes
None. This PR only adds new operators.
Migration Guide
No changes required for existing code. New operators are opt-in.
Checklist
Related