Two Unique Ways of Piping data in Elixir
Nov 20, 2018 .
1 min
read
No junk, straight to code
Assume data = {:ok, [1,2,3,4,5]} and we need to pass the data to the next function.
Do we need to write another function to do that job for this small operation? I don’t think so.
Check this…
TYPE –1 🎉
data
|> (fn {:ok, list} -> list end).()
|> length()
5

TYPE — 2 🎉
Here, instead of sending the length itself, I would like to send a message something looks like Total Images : 5 Do I again need to use inline function fn again here? I don’t think so.
Check this…
data
|> (& {:ok, list} -> list ).()
|> length()
|> (&"Total Images : #{&1}").()

Hope you like them. Thanks for reading…