``````### fn [![Build Status](https://img.shields.io/travis/artemeff/fn.svg)](https://travis-ci.org/artemeff/fn)

---

###### Function composition `(f ∘ g)(x) = f(g(x))`

```erlang
Fn = fn:compose(fun(X) -> X + X end, fun(X) -> X * 4 end)
Fn(10) % => 80
Fn(12) % => 96
```

---

###### Multiple function composition `(f ∘ g ∘ h)(x) = f(g(h(x)))`

```erlang
Fn = fn:compose(
[ fun(X) -> X + 3 end
, fun(X) -> X * 4 end
, fun(X) -> X - 2 end
])
Fn(10) % => 50
Fn(13) % => 62
```

---

###### Naive application `f \$ g \$ h \$ x = f(g(h(x)))`

```erlang
Val = fn:naive(
[ fun(X) -> X + 3 end
, fun(X) -> X * 4 end
, fun(X) -> X - 2 end
], 10),
Val % => 50
```

---

```erlang
[ fun(X) -> {ok, X + 3} end
, fun(X) -> {ok, X * 4} end
, fun(X) -> {ok, X - 2} end
], 10),
Val1 % => {ok, 50}

[ fun(X) -> {ok, X + 3} end
, fun(X) -> {ok, X * 4} end
, fun(_) -> {error, something_went_wrong} end
], 10),
Val2 % => {error, something_went_wrong}
```

---

###### Partial application

```erlang
Fn1 = fn:partial(fun lists:map/2, [fun erlang:list_to_atom/1])
Fn1(["test", "partial"]) % => [test, partial]

Fn2 = fn:partial(fun lists:foldl/3, [fun(X, Acc) -> X * Acc end, 1])
Fn2([2, 5, 10]) % => 100
```

---

### Contributing

1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)