Packages
mysql_client
1.2.8
MySQL native client is written in Erlang and provides API that is very close to Connector/C library.
Current section
Files
Jump to
Current section
Files
priv/maybe_monad_test.erl
%% @author alexeikrasnopolski
%% @doc @todo Add description to monad_test.
-module(maybe_monad_test).
-include_lib("eunit/include/eunit.hrl").
%% ====================================================================
%% API functions
%% ====================================================================
-export([continuation/1, f1/1, f2/1, f3/1]).
bind(F, C) -> fun(nothing) -> nothing; (A) -> C(F(A)) end.
return() -> fun(A) -> A end.
%% continuation([f1, f2, f3]) ->
%% bind(f1,
%% bind(f2,
%% bind(f3,
%% return)
%% )
%% )
%% .
continuation([]) -> return();
continuation([F | RF]) ->
bind(F, continuation(RF))
.
f_test() ->
Cont = continuation([fun f1/1,fun f2/1,fun f3/1]),
io:format(user, "*** Result = ~p~n", [Cont(0)]),
io:format(user, "*** Result = ~p~n", [Cont(1)]),
io:format(user, "*** Result = ~p~n", [Cont(2)]),
io:format(user, "*** Result = ~p~n", [Cont(3)])
.
%% ====================================================================
%% Internal functions
%% ====================================================================
f1(A) ->
io:format(user, "f1 >>> ~p~n", [A]),
case A of
3 -> nothing;
_ -> A + 1
end
.
f2(A) ->
io:format(user, "f2 >>> ~p~n", [A]),
case A of
3 -> nothing;
_ -> A + 1
end
.
f3(A) ->
io:format(user, "f3 >>> ~p~n", [A]),
case A of
3 -> nothing;
_ -> A + 1
end
.