Fl4m3Ph03n1x

Fl4m3Ph03n1x

Monadex bind operator

Background

I am trying a new library called Monadex and in specific I am trying the Result Monad. The documentation mentions a function called Result.bind and I have made it work with the following code snippet:

defmodule TestMonadex do
  use Monad.Operators

  import Monad.Result

  def p1(x) do
    x
    |> success()
    |> bind(&plus_1/1)
  end

  defp plus_1(n), do: n + 1
end

And so far so good.

Problem

The problem arises when I try to use the bind operator. According to the docs, this operator is the same thing as the Result.bind function. Following this logic, the following code snippet should work:

defmodule TestMonadex do
  use Monad.Operators

  import Monad.Result

  def p2(x) do
    success(x) ->> (&plus_1/1) # This does not compile!
  end

  defp plus_1(n), do: n + 1
end

Unfortunately, this is not compiling:

(SyntaxError) syntax error before: '>'

Stacktrace:
  │ (elixir 1.11.2) lib/kernel/parallel_compiler.ex:314: anonymous fn/4 in Kernel.ParallelCompiler.spawn_workers/7

an expression is always required on the right side of ->. Please provide a value after ->

At this point I strongly believe I am not understanding something from the docs or from the library.

Question

What a I doing wrong?

Marked As Solved

dorgan

dorgan

I still see a tilde, but the font choice may be a poor one and it’s easy to not spot the difference
It’s clearer looking at the source: MonadEx/lib/monad/operators.ex at master · rob-brown/MonadEx · GitHub
Or zooming:

Definitely an accessibility issue

Also Liked

dorgan

dorgan

The default one, it think it’s Arial since I’m on windows.
I do see the same as in your screenshot though, and the difference is barely noticeable.

Where Next?

Popular in Questions Top

bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
polypush135
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
lk-geimfari
What is most correct way to open, read and parse JSON file with poison? For example if we have example.json file in root of some projec...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New

Other popular topics Top

sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
977 41022 311
New
Tee
can someone please explain to me how Enum.reduce works with maps
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 45766 226
New
AstonJ
You’re a programmer, so you don’t need spoon feeding with the conventional drivel about “this is an integer.” No. You need to know what’s...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
johnnyicon
Hi all, I've just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I'm trying to use Postg...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New

We're in Beta

About us Mission Statement