Monads and other dark magic for Elixir
Finally, monads! Still could use more documentation, but they're here and they work 😄
[1, 2, 3] >>> fn x ->
[x + 1] >>> fn y ->
[y * x, y * 10, x - 1]
end
end
#=> [2, 20, 0, 6, 30, 1, 12, 40, 2]
[1, 2, 3]
>>> fn x -> [x + 1] end
>>> fn y -> [y * 10, y - 1] end
#=> [20, 1, 30, 2, 40, 3]
Of course they work on things other than lists. I'll will be moving the ADT-specifc implementations to Algae, so if you want Maybe
, Either
, and friends, please use it in conjunction with that library.
Still a bunch more to do, but this is already much better. Merging to master, and will continue to tighten stuff up and work through the roadmap.
Applicative Functors are here!
Things to note:
wrap
(i.e.: pure) & apply
are here!
apply
: <<~
and ~>>
apply
ping "over" things (apply [(+1)] [1,2,3]
)[1,2,3] ~>> [&(&1 + 1)]
)(\x y -> x + y) <$> [1,2,3] <*> [4,5,6]
&(&1 + &2) <~ [1,2,3] <<~ [4,5,6]
Kernel.apply
for modules
use
, or rename apply
(probably the later)Functor protocol, functions, and spot-check helpers
First draft of the Monoid
protocol