Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cjen07/param_pipe
parameterized pipe in elixir: |n>
https://github.com/cjen07/param_pipe
elixir metaprogramming pipe pipeline
Last synced: 10 days ago
JSON representation
parameterized pipe in elixir: |n>
- Host: GitHub
- URL: https://github.com/cjen07/param_pipe
- Owner: cjen07
- License: mit
- Created: 2017-07-18T14:12:38.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-10-15T07:49:45.000Z (about 6 years ago)
- Last Synced: 2024-09-22T20:42:00.960Z (about 2 months ago)
- Topics: elixir, metaprogramming, pipe, pipeline
- Language: Elixir
- Size: 12.7 KB
- Stars: 15
- Watchers: 1
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ParamPipe
## Prerequisite
* Erlang v21.0
* Elixir v1.7.3## Installation
```elixir
def deps do
[
{:param_pipe, "~> 0.2.0"}
]
end
```## Tests
```elixir
mix test
```## parameterized pipe in elixir: |n>
```elixir
use ParamPipedef foo(a, b, c) do
a*2 + b*3 + c*4
enddef bar0() do
100 |> div(5) |> div(2) # 10
end# negative n in |n> is supported
def bar1() do
1 |0> foo(0, 0) |1> foo(0, 0) |-1> foo(0, 0) # 24
end# mixed usage with |> is supported
def bar2() do
1
|> foo(0, 0) # 2
|1> foo(0, 0) # 6
|> div(2) # 3
|> div(3) # 1
|2> foo(0, 0) # 4
|> (fn x -> foo(0, 0, x) end).() # 16
|-1> foo(0, 0) # 64
end# assigning a variable within the pipe operator is supported
def bar3() do
h =
1
|-2> foo(0, 0) = f # 3 = f
|-1> foo(0, 0) # 12
|> foo(0, 0) = g # 24 = g
|-1> foo(0, 0) # 96
|> foo(f, g) # 297
h
end
```