[erlang-questions] Simple Erlang Recommendation (last returned value)

Tony Garnock-Jones <>
Fri Jul 25 18:36:45 CEST 2008


Berlin Brown wrote:
> NewQ = queue:new(),
> Queue1 = queue:add(joe, NewQ),
> Queue2 = queue:add(mike, Queue1), ...
> 
> queue:new(),
> queue:add(joe,  erlang:last_value()),
> queue:add(mike, erlang:last_value())), ...

%% Untested.
%% Use curried operations and a Haskell-like sequencing operator
%% to provide a kind of dataflow/pipeline style.

add(Elt) -> fun (Q) -> queue:add(Elt, Q) end.

seq(X, []) -> X;
seq(X, [F | Fs]) -> seq(F(X), Fs).

test() ->
   seq(queue:new(),
       [add(joe),
        add(mike)]).

%% Quite major language (and library!) changes would be needed to
%% make this feel properly natural.

%% Tony



More information about the erlang-questions mailing list