Skip to content

Latest commit

 

History

History
59 lines (51 loc) · 1.22 KB

README.md

File metadata and controls

59 lines (51 loc) · 1.22 KB

The f

GitHub Workflow Status Erlang Hex.pm

A collection of functions and types to make your Erlang code more functional, funky and/or fancy.

Examples

curry

Multiply = f:curry(fun erlang:'*'/2),
Triple = Multiply(3),
Triple(23).
% 69

flip

Get = (f:curry(fun maps:get/3))(a),
GetWithDefault = (f:flip(Get))(42),
GetWithDefault(#{}).
% 42

partial

Sum = f:partial(fun lists:foldl/3, [fun erlang:'+'/2, 0]),
Sum(lists:seq(1, 10)).
% 55

pipe

f:pipe(1, [
    (f:curry(fun erlang:'+'/2))(1),
    (fun(X) -> X * 2 end),
    (f:partial(fun lists:seq/3, [1, 50]))
]).
% [1,5,9,13,17,21,25,29,33,37,41,45,49]

do

f:do(2, [
   (fun(X) -> f:ok(X * 21) end),
   (fun(X) -> f:ok(X * 10) end)
]).
% {ok, 420}

f:do(1, [
   (fun(X) -> f:ok(X * 1) end),
   (fun(_) -> f:err(go_away) end),
   (fun(X) -> f:ok(X + 1) end)
]).
% {error, go_away}