Arrows - extended pipe operators (e.g. pipe to any argument position)

Provides OK-piping (similar to libraries like ok) and adds the ability to pipe into any argument position (similar to magritte) of the following function (or nested function). By inserting ... where you would like the value to be inserted, Arrows will override where it is placed.

This library was developed as part of the Bonfire project, which has some open bounties for any help improving performance: Bonfire Networks: An open-source framework for building federated digital spaces

So instead of only being limited to:

iex> 4 |> div(2)
2

You can also do:

iex> 4 |> div(2, ...)
0

Or even:

iex> 4 |> div(2, min(..., 1))
2

Links:

3 Likes

Ah, the three dots indicate where the object is put. Now I understand.

1 Like

That’s right! The documentation do with a rewrite… (have now edited the description to mention that)

1 Like

It is quite nice and readable :+1: However, it is also not so hard to replace with Kernel.then/2

could become

iex> 4 |> then(&div(2, &1))
0
4 |> then(&div(2, min(&1, 1)))
2
1 Like

Yeah this was created before then was introduced, so probably not needed if you’re used to that syntax.

I see that the main difference between this and Magritte is that it do not have my limitations. Actually I have intentionally added these limitations to avoid things like:

foo
|> bar(fn a ->
  a
  |> baz(2137, ...) # what value should be inserted there?
end)

Also, when you want to use ... twice within single pipe there is question whether there should be 2 separate parent pipes or single one. Aka whether this code:

:rand.uniform()
|> Kernel.==(..., ...)

Should always return true?

I probably should have describe reasoning better in Magritte documentation.

1 Like

Yeah that makes sense, though FWIW we’ve been happily using it without running into confusion on these topics so far.

In our case it pipes the same thing twice in that scenario:

    assert true = :rand.uniform()
    |> Kernel.==(..., ...)