flatmap
Thomas Johnsson
thomas@REDACTED
Mon Feb 27 14:38:49 CET 2006
The description seems correct except for the type of Function, which
should be:
Function = fun(A) -> [ B ] .
from lists.erl:
append([E]) -> E;
append([H|T]) -> H ++ append(T);
append([]) -> [].
....
flatmap(F, [Hd|Tail]) ->
F(Hd) ++ flatmap(F, Tail);
flatmap(_, []) -> [].
-- Thomas
Mats Cronqvist wrote:
> happended upon the description of lists:flatmap/2 (that i've never
> used), and was a bit mystified by the append/1 function used in the
> description. could it be that it should say flatten/1 ?
>
> mats
>
> flatmap(Function, List1) -> Element
> Types:
> Function = fun(A) -> B
> List1 = [A]
> Element = [B]
>
> flatmap behaves as if it had been defined as follows:
>
> flatmap(Func, List) ->
> append(map(Func, List))
>
More information about the erlang-questions
mailing list