From: Siraaj Khandkar Date: Sun, 10 Nov 2013 16:44:38 +0000 (-0500) Subject: Add result type module and define pipe. X-Git-Tag: 1.0.0~36 X-Git-Url: https://git.xandkar.net/?a=commitdiff_plain;h=6731749baadb46eda33393abbff36daae302cac8;p=hope.git Add result type module and define pipe. --- diff --git a/src/hope_result.erl b/src/hope_result.erl new file mode 100644 index 0000000..405f2e0 --- /dev/null +++ b/src/hope_result.erl @@ -0,0 +1,18 @@ +-module(hope_result). + +-export_type([ t/2 + ]). + +-export([ pipe/2 + ]). + + +-type t(A, B) :: {ok, A} | {error, B}. + + +pipe([] , X) -> X; +pipe([F|Fs], X) -> + case F(X) + of {error, _}=E -> E + ; {ok, Y} -> pipe(Fs, Y) + end.