Add 'compose/1', 'compose/2' functions
This commit is contained in:
parent
1c41302dad
commit
2ba624ac31
|
@ -23,6 +23,8 @@
|
||||||
|
|
||||||
-export([ merge_opts/2
|
-export([ merge_opts/2
|
||||||
, maybe_apply/2
|
, maybe_apply/2
|
||||||
|
, compose/1
|
||||||
|
, compose/2
|
||||||
, run_fold/3
|
, run_fold/3
|
||||||
, pipeline/3
|
, pipeline/3
|
||||||
, start_timer/2
|
, start_timer/2
|
||||||
|
@ -61,6 +63,15 @@ maybe_apply(_Fun, undefined) ->
|
||||||
maybe_apply(Fun, Arg) when is_function(Fun) ->
|
maybe_apply(Fun, Arg) when is_function(Fun) ->
|
||||||
erlang:apply(Fun, [Arg]).
|
erlang:apply(Fun, [Arg]).
|
||||||
|
|
||||||
|
-spec(compose(list(F)) -> G when F :: fun((any()) -> any()),
|
||||||
|
G :: fun((any()) -> any())).
|
||||||
|
compose([F|More]) -> compose(F, More).
|
||||||
|
|
||||||
|
-spec(compose(fun((X) -> Y), fun((Y) -> Z)) -> fun((X) -> Z)).
|
||||||
|
compose(F, G) when is_function(G) -> fun(X) -> G(F(X)) end;
|
||||||
|
compose(F, [G]) -> compose(F, G);
|
||||||
|
compose(F, [G|More]) -> compose(compose(F, G), More).
|
||||||
|
|
||||||
%% @doc RunFold
|
%% @doc RunFold
|
||||||
run_fold([], Acc, _State) ->
|
run_fold([], Acc, _State) ->
|
||||||
Acc;
|
Acc;
|
||||||
|
|
Loading…
Reference in New Issue