Does anyone make regular use of functional programming patterns like functors, monads and applicatives in Elixir?

Hi all,

As the title suggests, I’m curious to know if anyone makes effective use of the mentioned patterns (as well as other similar ones). I started learning these concepts through Scala and I’m having a hard time digesting this information. Even though Elixir is a functional programming language, fortunately, I haven’t seen these same concepts used as much here although I have seen a few relevant libraries like Witchcraft. I sense that for whatever reason, these patterns are not particularly popular in Elixir and I’d also be curious to hear why that is so. Any thoughts or opinions on this topic are welcomed :slight_smile:

  • {:ok, val}/{:error, val} tuples are monads
  • Plug.Conn is state monad
  • with is do-like notation

IMO the terminology is not particularly popular, but the ideas are all over the place. For instance, you can spot a free monad if you squint at gen_statem transition actions just right, or the Absinthe middleware pipeline where middlewares can return data that affects the middleware stack like self-modifying code.


Thanks @al2o3cr and @hauleth, I guess the ideas are indeed very much present in Elixir code, even though it isn’t immediately apparent to someone with poor FP knowledge (like me) :slight_smile:

There are not something like function compose exist in elixir. |> is like pipe in shell,not the pipe in fp.

Like what I just find in this post.

If we use the fp assume in elixir,like what I assume the chian of Enum.maps will compose to one map call, the code will slow.