ArrayFlatMap
Maps each element and flattens the result one level.
values = [ 1, 2, 3 ];
values.flatMap( ( value ) => [ value, value * 10 ] );
// [ 1, 10, 2, 20, 3, 30 ]
Method Signature
ArrayFlatMap(array=[array], callback=[function:Function], parallel=[boolean], maxThreads=[any], virtual=[boolean])Arguments
array
array
true
The array to transform
callback
function:Function
true
The function to invoke for each item. The function will be passed 3 arguments: the current item, and the current index, and the original array. You can alternatively pass a Java Function which will only receive the 1st arg.
parallel
boolean
false
If true, the function will be invoked in parallel using multiple threads. Defaults to false.
false
maxThreads
any
false
The maximum number of threads to use when parallel is true. If not provided the common thread pool will be used. If a boolean value is passed, it will be assigned as the virtual argument.
virtual
boolean
false
If true, the function will be invoked using virtual thread. Defaults to false. Ignored if parallel is false.
false
Examples
Transform each element and flatten the result one level
Each callback result is expected to be an array, and all results are flattened into a single array.
Result: [1, 10, 2, 20, 3, 30]
Expand a list of orders into individual items
Result: 3
Using the global function form
Result: [1, 2, 2, 3]
Related
Last updated
Was this helpful?
