Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elixir: Observables

Elixir streams provide iterables, but I couldn't find any information on observables (Google was no help here). I'd greatly appreciate it if someone could point me to resources for the same.

like image 857
tldr Avatar asked Dec 12 '25 23:12

tldr


1 Answers

You can combine Stream and Enum to write observable-style code. Here's an example of an echo server written in observable fashion:

IO.stream(:stdio, :line) 
|> Stream.map(&String.upcase/1)
|> Enum.each(&IO.write(&1))

Basically, for each line you send to standard input, it will be converted to uppercase and then printed back to standard output. This is a simple example, but the point is that all you need to compose an observable is already available via Stream and Enum.

like image 118
bitwalker Avatar answered Dec 16 '25 09:12

bitwalker