installation and usage
npm install powerseq
executing single operator
import { filter } from "powerseq";
for(var item of filter([1,2,3,4,5], x => x % 2 === 0)){
console.log(item);
}
chaining many operators
import { Enumerable } from "powerseq/enumerable";
// use 'Enumerable' class ONLY on the server side !! (use 'pipe' method on the client side )
const items = Enumerable
.range(1,Number.MAX_VALUE)
.filter( x => x % 2 === 0)
.take(5)
.reverse()
.toarray();
console.log(items);
chaining many operators using pipe method (it allows code tree shaking)
import { pipe, range, filter, take, reverse, toarray } from "powerseq";
const items = pipe(
range(1, Number.MAX_VALUE),
filter(x => x % 2 === 0),
take(5),
reverse(),
toarray());
console.log(items);
most of the operators can be used as a single operator (filter([1,2,3,4,5], x => x % 2 === 0)
) or as a part of the operator chain pipe([1, 2, 3, 4, 5], filter(x => x % 2 === 0), ... )
.But some operators have special counterparts (concatp, defaultifemptyp, includesp, sequenceequalp, zipp) when used with pipe, so we call concat([1,2,3], [4,5,6])
but we have to call pipe([1,2,3], concatp([4,5,6]), ... )
if we want to chain concat
with other operators.
operators
- each operator below has tooltip with documentation
- click to see mapping powerseq operators to LINQ, RxJS, JS Array, lodash, F#
enumerable
defer | range |
empty | repeatvalue |
entries | throww |
from | |
generate | |
of |