Calls Fun(Elem) on successive elements Elem of List1. Fun/1 must return either a Boolean or a tuple {true, Value}. The function returns the list of elements for which Fun returns a new value, where a value of true is synonymous with {true, Elem}.
That is, filtermap behaves as if it had been defined as follows:
filtermap(Fun, List1) ->
lists:foldr(fun(Elem, Acc) ->
case Fun(Elem) of
false -> Acc;
true -> [Elem|Acc];
{true,Value} -> [Value|Acc]
end
end, [], List1).
Example:
> lists:filtermap(fun(X) -> case X rem 2 of 0 -> {true, X div 2}; _ -> false end end, [1,2,3,4,5]).
[1,2]
seq(From, To) -> Seq
seq(From, To, Incr) -> Seq
Types
From = To = Incr = integer()
Seq = [integer()]
Returns a sequence of integers that starts with From and contains the successive results of adding Incr to the previous element, until To is reached or passed (in the latter case, To is not an element of the sequence). Incr defaults to 1.
Failures:
If To < From - Incr and Incr > 0.
If To > From - Incr and Incr < 0.
If Incr =:= 0 and From =/= To.
The following equalities hold for all sequences:
length(lists:seq(From, To)) =:= To - From + 1
length(lists:seq(From, To, Incr)) =:= (To - From + Incr) div Incr
Combines the elements of three lists of equal length into one list. For each triple X, Y, Z of list elements from the three lists, the element in the result list is Combine(X, Y, Z).
zipwith3(fun(X, Y, Z) -> {X,Y,Z} end, List1, List2, List3) is equivalent to zip3(List1, List2, List3).