Tech Tip: New .flatMap() function in the Collection Class
PRODUCT: 4D | VERSION: 20 | PLATFORM: Mac & Win
Published On: September 19, 2023
As of 4D v20, the flatMap() function can be called on a Collection.
The flatMap() function creates a new collection based upon the result of the call of the formula 4D or methodName method on each element of the original collection and flattened by a depth of 1.
Optionally, you can pass parameters to formula or methodName using the param parameter(s).
Notes:
• This function is identical to a map() call followed by a flat() call of depth 1.
• This does not modify the original collection.
Example:
var $col; $result : Collection $col:=New collection("Hello world"; ""; "are you there ?") $result:=$col.map(Formula(Split string($1.value; " "))) // [["Hello", "world"], [], ["are", "you", "there", "?"]] $result:=$col.flatMap(Formula(Split string($1.value; " "))) // ["Hello", "world", "are", "you", "there", "?"] |