baconjs / bacon.js

Functional reactive programming library for TypeScript and JavaScript
https://baconjs.github.io
MIT License
6.47k stars 330 forks source link

Reactive-node.js #391

Closed ken-okabe closed 10 years ago

ken-okabe commented 10 years ago

Perhaps, it's time to implement a bridge between bacon.js and node.js.

Everything in terms of IO of node is stream, and bacon.js is about (event) stream.

If we have a bridge, it will be called Reactive-node.js

A certain discussion I found: https://groups.google.com/forum/#!topic/baconjs/-epQIO_d8_Y

raimohanska commented 10 years ago

I'd like someone with the necessary experience to submit a PR. If the solution is simple enough, this could even go to the Bacon core along with Bacon.fromNodeCallback.

ken-okabe commented 10 years ago

After posting this issue, I reconsidered.

First of all, node stream such as piping every event is quite different approach to FRP that every event is mapped on the timeline.

There's

https://github.com/dominictarr/event-stream

EventStream is like functional programming meets IO

Streams are node's best and most misunderstood idea, and EventStream is a toolkit to make creating and working with streams easy.

Normally, streams are only used for IO, but in event stream we send all kinds of objects down the pipe. If your application's input and output are streams, shouldn't the throughput be a stream too?

The EventStream functions resemble the array functions, because Streams are like Arrays, but laid out in time, rather than in memory.

All the event-stream functions return instances of Stream.

Probably, this is the most well-done implementation around the web, and you can marge his work since it's MIT license, but again, I wonder if it's adequate to deal node stream in FRP framework.

For instance, there is socket.io ver.1.0. or engine.io It's not node stream, but bare event model.

I would not convert them to node stream, then FRP framework, instead, I simply map event to FRP stream.

Bartvds commented 10 years ago

If you want to get fancy with node streams you probably like https://www.npmjs.org/package/highland even more then event-stream.

It is much like Bacon but also take ideas from lazy-evaluation like Lazy.js, and it supports backpressure which is good for working with IO bound streams.

ken-okabe commented 10 years ago

Very interesting, well documented project. I will throughly investigate. Thanks for your input, Bartvds.