paldepind / flyd

The minimalistic but powerful, modular, functional reactive programming library in JavaScript.
MIT License
1.56k stars 85 forks source link

liftAllObj #75

Open ccorcos opened 8 years ago

ccorcos commented 8 years ago

I have a suggestion for lifting an object of streams.

liftAllObj = (signals) ->
  labeled = ([name, stream]) ->
    flyd.map(
      (value) -> {"#{name}": value}
      stream
    )

  streams = R.pipe(
    R.toPairs
    R.map(labeled)
  )(signals)

  reducer = (acc, next) ->
    flyd.lift(R.merge, acc, next)

  R.reduce(reducer, R.head(streams), R.tail(streams))

obj = 
  x: flyd.stream(1)
  y: flyd.stream(2)
  z: flyd.stream(2)

s = liftAllObj(obj)

flyd.on(console.log.bind(console), s)

obj.x(10)
obj.y(20)
obj.z(30)
c-dante commented 8 years ago

I dig it, why not make a PR for it as a module?