Skip to content

Instantly share code, notes, and snippets.

@msackman
Created March 30, 2011 15:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save msackman/894598 to your computer and use it in GitHub Desktop.
Save msackman/894598 to your computer and use it in GitHub Desktop.
Before:
-module(test_do).
-compile({parse_transform, erlando}).
-compile(export_all).
test_maybe(Arg) ->
do([maybe
|| X <- return(Arg),
case is_atom(Arg) of
true -> fail(argh);
false -> return(io:format("~p~n", [X]))
end,
return(ok)]).
-module(maybe).
-compile(export_all).
'>>='({just, X}, Fun) -> Fun(X);
'>>='(nothing, _Fun) -> nothing.
'>>'({just, _X}, Fun) -> Fun();
'>>'(nothing, _Fun) -> nothing.
return(X) -> {just, X}.
fail(_X) -> nothing.
After:
-module(test_do).
-compile(export_all).
test_maybe(Arg) ->
maybe:'>>='(maybe:return(Arg),
fun (X) ->
maybe:'>>'(case is_atom(Arg) of
true -> maybe:fail(argh);
false ->
maybe:return(io:format("~p~n", [X]))
end,
fun () -> maybe:return(ok) end)
end).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment