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

David Terrell dbt@REDACTED
Fri Jul 25 22:00:16 CEST 2008


Thomas Lindgren wrote:
> --- On Fri, 7/25/08, Berlin Brown <berlin.brown@REDACTED> wrote:
>> I wish there were something like this to get the result of
>> the last call
>>
>> queue:new(),
>> queue:add(joe,  erlang:last_value()),
>> queue:add(mike, erlang:last_value())), ...
> 
> It's probably better to get more familiar with functional programming, which instead of updating state passes around values.
> 
> How about this?
> 
> lists:foldl(
>    fun(X, Last_value) -> queue:add(X, Last_value) end,
>    queue:new(),
>    [joe, mike]).
> 

8> lists:foldl(fun queue:in/2, queue:new(), [joe, mike]).
{[mike],[joe]}



More information about the erlang-questions mailing list