0.0.3 • Published 8 years ago

highland-range v0.0.3

Weekly downloads
1
License
MIT
Repository
github
Last release
8 years ago

highland-range

Build Status

Filter a range from a highland stream. This is an optimized filter when you know that your stream is ordered with respect to the filter predicate, ie. your predicate will hold for all consecutive items after the first one it holds for.

You can supply a predicate start for defining the start of the range, and an end to define the end. Both are optional.

In some other languages these are called dropUntil and takeWhile respectively, but I didn't fancy creating two separate libraries.

Install

npm install highland-range

Examples:

var _ = require('highland')
var range = require('highland-range')
_([0, 1, 2, 3, 4])
  .consume(range()) // => 0, 1, 2, 3, 4
_([0, 1, 2, 3, 4])
  .consume(range(function start (x) { return x > 1 }))
  // => 2, 3, 4

_([0, 1, 2, 3, 4]).consume(range(undefined, function end (x) { return x < 4 }))
 // => 0, 1, 2, 3

 _([0, 1, 2, 3, 4])
  .consume(range(
    function start (x) { return x > 1 },
    function end (x) { return x < 4 }))
  // => 2, 3

Note that it is your responsibility to make sure that actual data satisfies partial ordering with respect to the predicates.

You can work with arbitrary data types.

Usage

range(start, end)

Accepts a start and an end function (both optional), and returns a highland stream.

  • start should accept a stream element and return a boolean meaning the predicate holds. While false, all items are dropped. This is sometimes called dropUntil.

  • end should accept a stream element and return a boolean meaning the predicate holds. Once false, this item and all consecutive ones are dropped. This is sometimes called takeWhile.

Contributors

@szdavid92 - David Szakallas

License

Copyright (c) 2016 David Szakallas

MIT License

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago