Elixir vs ReactiveX

Are there any Elixir libraries which are similar to the Reactive Extensions? For example rxpy or rxjs ? I have been using rxpy and find it amazing. I know it is fairly easy to replicate this with Erlang/Elixir “primitives” but it’s still quite a lot more work to re-implement many of the operators. Is GenStage supposed to kind of do the same thing as ReactiveX? Any other, well-maintained, library for reactive programming?

Any advice on functional reactive programming in general in Elixir?

1 Like

This thread might be helpful Reactive in Elixir

Then there are these two projects on github (they seem abandoned though):

As someone who sometimes uses rxswift, I’ve never had a need in rx in elixir …

1 Like

ReactiveX programming isn’t FRP.

Research into Functional Reactive Programming was popularized by Conal Elliot back in 2008 - though it actually goes back to his 1997 paper “Functional Reactive Animation” with Paul Hudak.

The Essence and Origins of FRP

2 Likes

Yeah I know that the purists get all hot and bothered about ReactiveX being called FRP.

Still for guys who need to actually ship stuff, this looks close enough. It’s functional, it’s reactive. It gets stuff done. It abstracts away time in a very effective way.

My question is not dogmatic. It’s a practical question about how one goes about doing RX style work in Elixir. RX is a great framework. I know that RX can be replicated using Erlang/Elixir primitives, but I just kind of wanted to know if there were any libraries which give me a higher level access and do some of the boilerplate for me.

Now if you tell me there’s something even better that’s even purer etc, then I’d love to hear about it. But my primary goal is shipping product.

My use case is streaming data coming in, being transformed, being visualized by users. Said users must be able to interact with the transforation algos ie. change the parameters of the transformations. RX does a fantastic job at that. But I want to work in Elixir, not Python because the VM and proper pre-emptive processes are so addictive.

I will read the papers you point to though - thank you - maybe a bit of theory will tranform my outlook :grin:

Okay that thread is mighty useful.

Thing is RX is capable of doing Excel-style DAG work (though admittedly not dynamic, unlike Incremental). So now I’m a bit confused as to how I get this done in Elixir.

Incremental from Jane Street in Ocaml, for example, seems absolutely amazing.

1 Like

Hmmm…

Reactive Extensions solve certain problems well in certain environments.

It just so happens that being “reactive” is only one single concern that any Erlang/Elixir solution design/architecture has to address. How “reactive” a solution is depends on certain design choices.

But in my opinion a problem that Rx is suited for is probably too large to fit in a single BEAM process (where everything happens sequentially) and once you break up the problem across multiple BEAM processes the use case for Rx typically goes away.

Some data stream transformation can be handled with GenStage - visualization would likely be a separate (front end) concern but I guess Phoenix channels could be used to inform the users of the transformation progress.

Imagine a BEAM process for every active cell in a spreadsheet - only each process can send an event to any other process that it knows about; incoming events are (usually) processed in the order they arrive; typically a single process has more responsibility than a single spreadsheet cell. Code execution within any one process is strictly sequential. Concurrency happens between processes.

2 Likes

“the case for RX typically goes away”

That is what I suspected, and I think I’ll just stick to Elixir processes. It’s true that RX is in some ways “tacked on” and it cries out for concurrency, which is handled quite hack-style in the Python implementation.

I must say I’m intrigued, having glossed your links, about the idea of proper continuity, as opposed to the more pragmatic sampling approach inevitably taken by Rx (and my imperative brain). “Symbolic” differentiation and integration in a pure sense would be very interesting for my use case.

I think basically what I’m hearing, from you and the other commentator, “Idiot”, is that RX is moot if I stick to Elixir.

(Unfortunately I still have to plug Python in somehow because I need big calcs using Numpy and GPU, but I’ll handle that - I’ll stick a BEAM process onto each Python process using NIFs or the other interop libs. If I recall correctly Erlang 20 has made some big safety steps on this ie ways of linking in to to C (and therefore Python) libs without endangering the safety of the VM).

For the time being you can use Pyrlang to reuse what you already have - then Erlang/Elixir can interact with that Python code (and the C code doing the real work) just like with any other node.

See also Elixir call python by ports.

2 Likes

@peerreynders do you have experience with Pyrlang? I’d love to use it but it seems that you can only use it on the same physical machine, using address 127.0.0.1? Have you been able to run a full python node over a network, i.e. one machine has elixir (or erlang) node on it and another machine has Pyrlang python node on it? I can’t seem to be able to get them to see each other as per this issue I have raised:

https://github.com/esl/Pyrlang/issues/17

No sorry I haven’t.

Though I did notice some “127.0.0.1” hardcoding here but as I’m currently unfamiliar with Python and gevent that may actually be exactly what is needed.

I wish I could help.

Many thanks anyway. I have taken the liberty of pointing this hardcoded address out on the github issue.

1 Like