Mon Feb 27 14:38:49 CET 2006
The description seems correct except for the type of Function, which
Function = fun(A) -> [ B ] .
append([E]) -> E;
append([H|T]) -> H ++ append(T);
append() -> .
flatmap(F, [Hd|Tail]) ->
F(Hd) ++ flatmap(F, Tail);
flatmap(_, ) -> .
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 ?
> flatmap(Function, List1) -> Element
> 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