Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

highland-repartition

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

highland-repartition

Repartition a highland stream on your own criteria

  • 0.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

highland-repartition

Build Status

Repartition a highland stream on your own criteria. This module helps you with partitioning strings into lines, arrays into subarrays etc., theoretically anything as long as you can supply a function that splits and one that concatenates.

Install

npm install highland-repartition

Examples:


var _ = require('highland')
var repartition = require('highland-repartition')

_([
  'Often Guests forget', 'their things,\n',
  'Leave their hats, their coats and rings\r\n',
  'Other people leave their stains,\r', '\n',
  'Leave their shadows leave their pains'
]).consume(repartition(
  function split (x) { return _(x.split(/\r?\n/)) },
  function concat (x0, x1) { return x0 + x1 }
))

// =>
//   Often Guests forget their things,
//   Leave their hats, their coats and rings,
//   Other people leave their stains,
//   Leave their shadows leave their pains

Note that this works even on the 3rd line, where the pattern is split apart. This is because every non-matching part will concatenated and fed into the splitter until it is matched.

To work on arbitrary input streams, the concatenating operator also has to be supplied.

Let's see a bit more complicated example:


var _ = require('highland')
var repartition = require('highland-repartition')

_([
    [1, 2, 3, 4, 5, 1, 2, 3],
    [],
    [4, 5, 6, 1, 2, 3, 4, 1]
]).consume(repartition(
  function split (xs) {
    if (xs.length === 0) {
      return _()
    } else {
      var buffers = [[]]
      var end = 0
      var last = xs[0]
      xs.forEach(function (x) {
        if (x < last) {
          buffers[++end] = [x]
        } else {
          buffers[end].push(x)
        }
        last = x
      })
      return _(buffers)
    }
  },
  function concat (x0, x1) {
    return x0.concat(x1)
  }
))
// =>
//   [
//    [1, 2, 3, 4, 5],
//    [1, 2, 3, 4, 5, 6],
//    [1, 2, 3, 4],
//    [1]
//  ]

Usage

repartition(split, concatenate)

Accepts a split and a concatenate function (both required), and returns a highland stream.

  • split should accept an stream element and return a highland stream of elements.

  • concatenate should accept two stream elements and return one stream element.

Contributors

@szdavid92 - David Szakallas

License

Copyright (c) 2016 David Szakallas

MIT License

Keywords

FAQs

Package last updated on 10 Sep 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc