This is the legacy 4D documentation web site. Documentations are progressively being moved to developer.4d.com

Home

 
4D v19.8
collection.map( )

collection.map( ) 


 

collection.map ( methodName {; param}{; param2 ; ... ; paramN} ) -> Function result 
Parameter Type   Description
methodName  Text in Name of method used to transform the collection elements
param  Expression in Parameter(s) for the method
Function result  Collection in Collection of transformed values

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
Number: 805252

This command can be run in preemptive processes

 
PAGE CONTENTS 
 
HISTORY 

Created: 4D v16 R6

 
ARTICLE USAGE

4D Language Reference ( 4D v19)
4D Language Reference ( 4D v19.1)
4D Language Reference ( 4D v19.4)
4D Language Reference ( 4D v19.5)
4D Language Reference ( 4D v19.6)
4D Language Reference ( 4D v19.7)
4D Language Reference ( 4D v19.8)