• Stars
    star
    109
  • Rank 319,077 (Top 7 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created almost 8 years ago
  • Updated 10 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Sequence operators

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

enumerable

deferrange
emptyrepeatvalue
entriesthroww
from
generate
of
operators
asiterablefiltermaxskiplast
averagefindmaxbyskipwhile
bufferfindindexminsome
castflatmapminbysum
concatforeachoftypetake
countgroupbyorderbytakelast
defaultifemptygroupjoinorderbydescendingtakewhile
distinctignoreelementsreducethenby
distinctuntilchangedincludesrepeatthenbydescending
doointersectreversetoarray
elementatisemptyscantomap
everyjoinsequenceequaltoobject
exceptlastsingleunion
expandmapskipzip