Method map()
- Method map
mixedmap(mixedarr,void|mixedfun,mixed...extra)- Description
Applies
funto the elements inarrand collects the results.arris treated as a set of elements, as follows:- array
- multiset
- string
funis applied in order to each element. The results are collected, also in order, to a value of the same type asarr, which is returned.- mapping
funis applied to the values, and each result is assigned to the same index in a new mapping, which is returned.- program
The program is treated as a mapping containing the identifiers that are indexable from it and their values.
- object
If there is a lfun::cast method in the object, it's called to try to cast the object to an array, a mapping, or a multiset, in that order, which is then handled as described above.
funis applied in different ways depending on its type:- function
funis called for each element. It gets the current element as the first argument andextraas the rest. The result of the call is collected.- object
funis used as a function like above, i.e. the lfun::`() method in it is called.- array
Each element of the
funarray will be called for each element ofarr.- multiset
- mapping
funis indexed with each element. The result of that is collected.- "zero or left out"
Each element that is callable is called with
extraas arguments. The result of the calls are collected. Elements that aren't callable gets zero as result.- string
Each element is indexed with the given string. If the result of that is zero then a zero is collected, otherwise it's called with
extraas arguments and the result of that call is collected.This is typically used when
arris a collection of objects, andfunis the name of some function in them.
- Note
The function is never destructive on
arr.- See also
filter(), enumerate(),
foreach()