Method map()
- Method
map
mixedmap(mixedarr,void|mixedfun,mixed...extra)- Description
Applies
funto the elements inarrand collects the results.- Parameter
arr arris treated as a set of elements, as follows:arrayfunis applied in order to each element. The results are collected, also in order, to a value of the same type asarr, which is returned.mappingfunis applied to the values, and each result is assigned to the same index in a new mapping, which is returned.programThe program is treated as a mapping containing the identifiers that are indexable from it and their values.
objectIf 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.
- Parameter
fun funis applied in different ways depending on its type:function(mixed... :mixed)funis called for each element. It gets the current element as the first argument andextraas the rest. The result of the call is collected.objectfunis used as a function like above, i.e. the lfun::`() method in it is called.arrayEach element of the
funarray will be called for each element ofarr.multisetfunis indexed with each element. The result of that is collected.zero|voidEach 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.stringEach 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()