flyd-droprepeats
v2.0.1
Published
Drop repeated values with Flyd
Downloads
10
Readme
flyd-droprepeats
Drops consecutively repeated values from a Flyd stream.
API
dropRepeats(s)
Drops repeated values from stream s
. Equality is determined by reference.
Signature
Stream a -> Stream a
Usage
var dropRepeats = require('flyd-droprepeats').dropRepeats;
var append = function(arr, x) {
return arr.concat(x);
};
var s = flyd.stream();
var noRepeats = dropRepeats(s);
var collect = flyd.scan(append, [], noRepeats);
s(1)(2)(2)(3);
collect() // [1, 2, 3]
dropRepeatsWith(fn, s)
Drops repeated values from stream s
, but also takes a function fn
that
will be used to determine equality.
Signature
(a -> b -> Boolean) -> Stream a -> Stream a
var dropRepeatsWith = require('flyd-droprepeats').dropRepeatsWith;
var s = flyd.stream();
// Ramda's `equals` determines equality by value
var noRepeats = dropRepeatsWith(R.equals, s);
var collect = flyd.scan(append, [], noRepeats);
s({ foo: 'bar' });
s({ foo: 'bar' });
collect() // [{ foo: 'bar' }]