pipeline-linq
sync/async generators and helpers to form typed linq-like iterable queries
this is an experimental package and subject to change on minors versions
Install
install with either npm or yarn:
npm install pipeline-linq
yarn add pipeline-linq
Dependencies
For versions pipeline-linq @ < 1.0
, this package, when imported, will polyfill the Symbol.asyncIterator
using core-js
.
Basic Usage
linq
is a helper function used to wrap and chain pipeline methods together. Simply pass through an object that implements [Symbol.iterator]
, this includes []
or any typed-array.
; console.logresult;
By default the call to linq
returns the synchronous query, you can switch to the async equivalents by passing through true
at the end of most supporting methods.
Converting to an async query will cause all subsequent method calls to be evaluated using the Symbol.asyncIterator
and you must await the resulting promise or use for-await
to iterate the query.
; main;
note: when using
linq
the evaluation of the iterators is lazy, thus you can iterate overquery
multiple times.
Generators
You can use the sync generators directly by importing them:
; ; ;;;
Advanced Usage
The Linq and LinqAsync interfaces have a method chain
that can be used to insert custom iterators into the iterator sequence.
A custom filter method:
; .chainisNumber .toArray;
It is also possible to insert complex queries:
; .chainisNumber .chainquery .skip1 .toArray;
Pipeline Operator
see proposal pipeline-operator
Subject to change. All generators and helper methods take the source as the first parameter and so will be readily available to use with the pipeline operator. For now, you could use the babel transformer and use:
; |> where_, x > 2 |> select_, x * 2 |> first;