paldepind / flyd

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

endsOn not being curried #169

Closed ricardo-devis-agullo closed 6 years ago

ricardo-devis-agullo commented 6 years ago

Why flyd.endsOn is not curried?

Other 2-param functions like map, or merge are, so I wonder if there's any reason behind it. I had in my code something like this:

const interval$ = R.compose(
  flyd.endsOn(stream$.end),
  flyd.debounceTime(bounceTime || 0),
  flyd.mergeAll
)(sources);

And had to convert it to

const interval$ = R.compose(
  stream => flyd.endsOn(stream$.end, stream),
  flyd.debounceTime(bounceTime || 0),
  flyd.mergeAll
)(sources);

to make it work. I was thinking of exporting myself a version of endsOn that is curried, but wondered if there's any problem doing that.

Thank you!

nordfjord commented 6 years ago

I think it's a hint that it's mutating the stream passed in.

There is a module called takeUntil. But that has its own problems e.g. the argument order is (src, end)

but it does not mutate your stream.

using takeUntil you could do:

const takeUntil = R.flip(require('flyd/module/takeuntil'));

const interval$ = R.compose(
  takeUntil(stream$.end),
  flyd.debounceTime(bounceTime || 0),
  flyd.mergeAll
)(sources);

It's also rather curious to see you've extended the flyd object. You could always just

flyd.endsOn = flyd.curryN(2, flyd.endsOn);
ricardo-devis-agullo commented 6 years ago

Oh, I see, I guess it makes sense. I didn't know that endsOn mutated the stream.

The takeUntil seems to do the trick :)

And yeah, I forgot to mention that I had an extended flyd object :P I don't change already existing methods, but I can always come up with a different name for the flipped takeUntil (I already had takeUntil on the extended flyd object ^_^)

Thanks!

nordfjord commented 6 years ago

Closing this as I think takeUntil solves it :smile: Feel free to reopen if you feel this hasn't been resolved properly.