4D v18

collection.map( )

Home

 
4D v18
collection.map( )

collection.map( )  


 

The collection.map( ) method creates a new collection based upon the result of the call of the methodName method on each element of the original collection. Optionally, you can pass parameters to methodName using the param parameter(s). collection.map( ) always returns a collection with the same size as the original collection.

Note: This method does not modify the original collection.

methodName receives the following parameters:

  • in $1.value (any type): element value to be mapped
  • in $2 (any type): param
  • in $N... (any type): param2...paramN

methodName sets the following parameter(s):

  • $1.result (any type): new transformed value to add to the resulting collection
  • $1.stop (boolean): true to stop the method callback. The returned value is the last calculated.

Example  

 C_COLLECTION($c;$c2)
 $c:=New collection(1;4;9;10;20)
 $c2:=$c.map("Percentage";$c.sum())
  //$c2=[2.27,9.09,20.45,22.73,45.45]

Here is the Percentage method:

 C_OBJECT($1)
 C_REAL($2)
 $1.result:=Round(($1.value/$2)*100;2)



See also 

collection.extract( )

 
PROPERTIES 

Product: 4D
Theme: Collections

This command can be run in preemptive processes

 
PAGE CONTENTS 
 
HISTORY 

 
ARTICLE USAGE

4D Language Reference ( 4D v18)