git ssb

2+

Dominic / pull-stream



Tree: a81d5b4839992b6e494921404deee61709e162bf

Files: a81d5b4839992b6e494921404deee61709e162bf / docs / throughs / flatten.md

825 bytesRaw

pull-stream/throughs/flatten

flatten = require('pull-stream/throughs/flatten')

example

test('flatten arrays', function (t) {
  pull(
    pull.values([
      [1, 2, 3],
      [4, 5, 6],
      [7, 8, 9]
    ]),
    pull.flatten(),
    pull.collect(function (err, numbers) {
      t.deepEqual([1, 2, 3, 4, 5, 6, 7, 8, 9], numbers)
      t.end()
    })
  )
})

test('flatten stream of streams', function (t) {

  pull(
    pull.values([
      pull.values([1, 2, 3]),
      pull.values([4, 5, 6]),
      pull.values([7, 8, 9])
    ]),
    pull.flatten(),
    pull.collect(function (err, numbers) {
      t.deepEqual([1, 2, 3, 4, 5, 6, 7, 8, 9], numbers)
      t.end()
    })
  )

})

usage

flatten(streams)

Turn a stream of streams or a stream of arrays into a stream of their items, (undoes group).

Built with git-ssb-web