Skip to content

Commit

Permalink
Update README with <~> operator
Browse files Browse the repository at this point in the history
  • Loading branch information
Brooklyn Zelenka committed Sep 12, 2016
1 parent c1498bb commit 1beb2d0
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,35 @@ operator `<|>` is done "the math way" (right-to-left).

Versions on lists also available.

```elixir
# Regular Composition

sum_plus_one = fn x -> x + 1 end <|> &Enum.sum/1
sum_plus_one.([1,2,3])
#=> 7

add_one = &(&1 + 1)
piped = [1,2,3] |> Enum.sum |> add_one.()
composed = [1,2,3] |> ((add_one <|> &Enum.sum/1)).()
piped == composed
#=> true

sum_plus_one = (&Enum.sum/1) <~> fn x -> x + 1 end
sum_plus_one.([1,2,3])
#=> 7

# Reverse Composition (same direction as pipe)
x200 = (&(&1 * 2)) <~> (&(&1 * 10)) <~> (&(&1 * 10))
x200.(5)
#=> 1000

add_one = &(&1 + 1)
piped = [1,2,3] |> Enum.sum |> add_one.()
composed = [1,2,3] |> ((&Enum.sum/1) <~> add_one).()
piped == composed
#=> true
```

## Common Combinators
A number of basic, general functions, including `id`, `flip`, `const`, `pred`, `succ`, `fix`, and `self_apply`.

Expand Down

0 comments on commit 1beb2d0

Please sign in to comment.