1.0.0 • Published 6 years ago

callbag-keep-sequences v1.0.0

Weekly downloads
6
License
ISC
Repository
github
Last release
6 years ago

callbag-keep-sequences

A callbag operator that passes through only sequences with minimum length.

// minimum streak length = 3
1, 2, 2, 2, 2, 3, 3, 1, 1, 1, 3 // input
   2, 2, 2, 2,       1, 1, 1    // output

npm version build status ISC-licensed chat with me on Gitter support me on Patreon

Installation

npm install callbag-keep-sequences

Usage

const pipe = require('callbag-pipe')
const fromIter = require('callbag-from-iter')
const keepSequences = require('callbag-keep-sequences')
const forEach = require('callbag-for-each')

pipe(
	fromIter([1, 2, 2, 2, 2, 3, 3, 1, 1, 1, 3]),
	keepSequences(2), // sequences with >= 2 items
	forEach(console.log)
)
// 2 2 2 2 1 1 1

API

keepSequences(n, compare = (a, b) => a === b)

Related

  • callbag spec – 👜 A standard for JS callbacks that enables lightweight observables and iterables
  • callbag-distinct-until-changed – Drops consecutive duplicate values. Works on either pullable or listenable sources.

Contributing

If you have a question or have difficulties using callbag-keep-sequences, please double-check your code and setup first. If you think you have found a bug or want to propose a feature, refer to the issues page.