githubEdit

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

Argument
Type
Required
Description
Default

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

Last updated

Was this helpful?