callbag-keep-sequences

1.0.0 • Public • Published

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.

Package Sidebar

Install

npm i callbag-keep-sequences

Weekly Downloads

1

Version

1.0.0

License

ISC

Unpacked Size

4.72 kB

Total Files

4

Last publish

Collaborators

  • derhuerst