Skip to content

Instantly share code, notes, and snippets.

@pemrouz
Created March 27, 2017 18:41
Show Gist options
  • Save pemrouz/62e5074ee1104306803148816cada7ac to your computer and use it in GitHub Desktop.
Save pemrouz/62e5074ee1104306803148816cada7ac to your computer and use it in GitHub Desktop.
flatmap api?
const o = emitterify()
, stream1 = emitterify()
, stream2 = emitterify()
// without
o.on('primary')
.map(d => console.log(d)) // stream1, stream2
// with
o.on('primary')
.map(flatten('secondary'))
.map(d => console.log(d)) // 1a, 1a, 2a, 2b
o.emit('primary', stream1)
.emit('primary', stream2)
stream1.emit('secondary', '1a')
stream1.emit('secondary', '1b')
stream2.emit('secondary', '2a')
stream2.emit('secondary', '2b')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment