Sometimes you want to iterate over a set once and split the set into two separate usable piles.
This does that!
const sieve =const yes no =console // [1, 1]console // // works with any iterable:const yes no =console // [1, 2]console // 
$ npm install --save @iterables/sieve
sieve(iterable:Iterator<T>, test:Function) -> [Iterator<T>, Iterator<T>]
iterable: any iterable (generator instance,
test: a function taking
xs: an item from
idx: the index within the array.
all: the original iterable
Returns a two-element array of iterators. The first element,
yes, is an
iterable of all items from the original iterable that pass the test function.
The second element,
no, contains all the failing items.
Note: this function will buffer the skipped items in the second iterable to be
realized. That is, if you evaluate the
yes iterable all at once first, all
failing elements will be buffered in
no until it is iterated. Usually realizing
the array is the goal, so keeping the elements in memory shouldn't be an issue.
If memory is an issue, consider taking one element at a time from
no, which will buffer at most
N items, where
N is the largest run of
all-passing or all-failing items.