paldepind / flyd

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

merge multiple #66

Closed jethrolarson closed 8 years ago

jethrolarson commented 9 years ago

I was banging my head against a problem for a while before realizing that flyd.merge is binary. For some reason I expected it to merge all arguments.

flyd.merge(a, b, c)

I wish js would throw on these kind of errors...

I guess this is more feedback than a bug. Close if you think it's not a problem.

paldepind commented 9 years ago

What about adding a mergeAll? It takes a list of streams and merges them all?

jethrolarson commented 9 years ago

Seems reasonable.

On Sat, Oct 17, 2015, 2:22 AM Simon Friis Vindum notifications@github.com wrote:

What about adding a mergeAll? It takes a list of streams and merges them all?

— Reply to this email directly or view it on GitHub https://github.com/paldepind/flyd/issues/66#issuecomment-148897735.

ccorcos commented 8 years ago

I was just thinking this... We could also use a clone.

flyd.clone = function(s) {
  return flyd.stream([s], function() { 
    return s()
  })
}

flyd.mergeAll = function(list) {
  if (list.length === 0) {
    return flyd.stream()
  } else if (list.length === 1) {
    return flyd.clone(list[0])
  } else {
    return R.reduce(flyd.merge, list[0], list.slice(1))
  }
}
jordalgo commented 8 years ago

I was also just looking for something like this. :+1:

jordalgo commented 8 years ago

here is a quick attempt: https://github.com/paldepind/flyd/pull/79

paldepind commented 8 years ago

This issue is solved thanks to the mergeAll module contributed by @jordalgo.