Skip to content

Latest commit

 

History

History
53 lines (37 loc) · 1.1 KB

README.md

File metadata and controls

53 lines (37 loc) · 1.1 KB

flyd-droprepeats

Drops consecutively repeated values from a Flyd stream. Equality is determined by reference.

dropRepeats(s)

Graph

a:              {---11--12-2-3-4-}
dropRepeats(a): {---1----2---3-4-}

Signature

Stream a -> Stream a

Usage

const dropRepeats = require('flyd/module/droprepeats').dropRepeats

const s = flyd.stream()
const noRepeats = dropRepeats(s)
const collect = flyd.scan((ls, n) => ls.concat(n), [], 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 -> a -> Boolean) -> Stream a -> Stream a

Usage

const dropRepeatsWith = require('flyd/module/droprepeats').dropRepeatsWith
const s = flyd.stream()

// Ramda's `equals` determines equality by value
const R = require('ramda')
const noRepeats = dropRepeatsWith(R.equals, s)
const collect = flyd.scan((ls, n) => ls.concat(n), [], noRepeats)
s({ foo: 'bar' })
s({ foo: 'bar' })
collect() // [{ foo: 'bar' }]