Working pipe operator today in pure JavaScript
4 days ago
- #JavaScript
- #Pipeline Operator
- #Functional Programming
- asPipes is an experimental runtime abstraction modeling the proposed |> pipeline operator using standard JavaScript (ES2020+).
- It leverages the bitwise OR operator (|) and Symbol.toPrimitive for pipeline-style composition.
- Supports both synchronous and asynchronous evaluation with deferred execution until .run() is called.
- Key features include composability, deferred execution, async-safety, statelessness, and ergonomic alignment with the future pipeline operator.
- Examples demonstrate string manipulation, numeric operations, async API calls, composable higher-order pipes, and stream processing with async generators.
- The implementation is small (<50 lines) and serves as a prototype to explore F#-style pipeline semantics in current JavaScript.
- Limitations include restricted right-hand side expressions and being purely demonstrative, not intended for production.
- Open questions explore future ECMAScript support, static analysis needs, and ergonomic improvements for the pipeline proposal.