immutable-js/immutable-js

Pairwise aggregation or "buffer" operator for Iterables

Open

#400 aperta il 19 mar 2015

Vedi su GitHub
 (2 commenti) (0 reazioni) (0 assegnatari)TypeScript (1774 fork)batch import
enhancementhelp wanted

Metriche repository

Star
 (33.046 star)
Metriche merge PR
 (Merge medio 12g 22h) (20 PR mergiate in 30 g)

Descrizione

Hi, I really like Immutable.js.

I am used to use RxJS, and it's nice that many of its operators have counterparts in Immutable.js. But I feel one of them is missing, and that would be an operator that aggregates consecutive values for you. In Rx, that would be buffer or "pairwise" in RxJS, or even the good old scan, which is like reduce but used for producing an Iterable, instead of one single "reduced" value.

Practically, what I would like to do is:

> let a = Immutable.List([1,2,3,4,5]);
List [ 1, 2, 3, 4, 5 ]

> let b = a.pairwise();
List [ List[1,2], List[2,3], List[3,4], List[4,5] ]

Naive groupBy doesn't work for that because it doesn't overlap the children lists.

Guida contributor