[erlang-questions] Pipe, maybe, and other silly parse transforms

Andreas Schultz <>
Sun Apr 2 12:55:19 CEST 2017


Hi Fred,

----- On Apr 2, 2017, at 12:38 AM, Fred Hebert  wrote:

> Hi everyone!
> 
> On this April 1st, I decided to do a few foolish things, and implement
> an Erlang equivalent to Elixir's Pipe along with a 'maybe' construct.

Out of curiosity, how does this differ from erlando's
(https://github.com/rabbitmq/erlando) `state` monad ?

The syntax does seem to a bit more pleasing, but as far as I can tell the
result is about the same.

Thanks,
Andreas

> The first ideas for this I had are almost 2 years old now and are
> archived at
> http://erlang.org/pipermail/erlang-questions/2015-July/085109.html
> 
> Well since today's a silly day, I spent a bit of time and made an actual
> version of it that can be toyed with, and put it in a library called
> 'fancyflow' (https://github.com/ferd/fancyflow)
> 
> You can now do fancy control flow refactorings to move from code like:
> 
>    String = "a b c d e f",
>    string:join(
>      lists:map(fun string:to_upper/1, string:tokens(String, " ")),
>      ","
>    ).
> 
> into:
> 
>    [pipe]("a b c d e f",
>           string:tokens(_, " "),
>           lists:map(fun string:to_upper/1, _),
>           string:join(_, ",")).
> 
> and change conditionals like:
> 
>    case file:get_cwd() of
>        {ok, Dir} ->
>            case file:read_file(filename:join([Dir, "demo", "data.txt"])) of
>                {ok, Bin} ->
>                    {ok, {byte_size(Bin), Bin}};
>                {error, Reason} ->
>                    {error, Reason}
>            end;
>        {error, Reason} ->
>            {error, Reason}
>    end.
> 
> into:
> 
>    [maybe](undefined,
>            file:get_cwd(),
>            file:read_file(filename:join([_, "demo", "data.txt"])),
>            {ok, {byte_size(_), _}}).
> 
> More details in the README.
> 
> I can't actually advise or recommend using the library, but I felt like
> sharing it anyway :)
> 
> Regards,
> Fred.
> _______________________________________________
> erlang-questions mailing list
> 
> http://erlang.org/mailman/listinfo/erlang-questions


More information about the erlang-questions mailing list