mayel

mayel

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:

Most Liked

Nefcairon

Nefcairon

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

mayel

mayel

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

tomekowal

tomekowal

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
hauleth

hauleth

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.

mayel

mayel

I’ve added some more docs and examples: Arrows — arrows v0.2.1

Regarding ~> I tend to use it mostly for short pipes where with may feel verbose, but for longer ones I prefer to be more explicit. In part because of this gotcha:

      # Note that the following would pass :error to `String.pad_leading` breaking our pipe: 
      # :error ~> Integer.to_string() |> String.pad_leading(2, "0")
      :error

      # Instead we want to do:
      iex> :error ~> Integer.to_string() ~> String.pad_leading(2, "0")
      :error

Where Next?

Popular in Libraries Top

hpopp
After just over two years in development, this latest version of Pigeon is what I finally consider done in regards to my original vision ...
New
tompave
Hello there, I would like to share a feature toggles library (AKA feature flags) I’ve been working on. The main package is FunWithFlags...
New
seancribbs
Today I released a new dialyzer Mix task as the dialyzex package! At the time we started writing this task, the existing dialyzer integra...
New
nikokozak
Hello all, I’ve been working on Svonix - a library for quickly integrating Svelte components into Phoenix views. It’s a much-needed succ...
New
wfgilman
I’ve cleaned up and open sourced three financial libraries I was using for my company. They are bindings for the APIs of these three comp...
New
asiniy
Hey there! I wrote a download elixir package which does exactly what its name about - an easy way to download files. I saw solutions ...
New
benlime
I created a new library GitHub - benvp/ex_cva: Class Variance Authority for Elixir which aims to make it very easy to define different va...
New
woylie
Flop is an Elixir library that applies filtering, ordering and pagination parameters to your Ecto queries. offset-based pagination with...
New
ericlathrop
I built a silly site for Halloween that uses Phoenix Channels on the backend, and React on the frontend. I had many problems integrating ...
New
New

Other popular topics Top

Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
quazar
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
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
danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 27727 240
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
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
Nvim
Elixir appears to be a superior language to Python. I don’t see any advantage of Python over Elixir. Are there any?
New

Sub Categories:

We're in Beta

About us Mission Statement