flatMap()

Create an Set by applying a Function to each Set element, then flatten the result by one level.

Signature

flatMap(function: (element: Any) => Set): Set

Description

The flatMap() method creates an Set by invoking function on each element of the calling Set and flattening the resulting set one level. The Set elements are passed as a parameter to function, sequentially.

The calling Set isn’t changed.

Parameters

Parameter Type Required Description

function

Function

Yes

Function to invoke for each Set element that the Set represents. Each Set element is passed to function as an argument. function must return an Set

function parameters:

Parameter Type Required Description

element

Any

Yes

Set element to evaluate.

Return value

Type Description

Set

A new Set that consists of the results of calling function on each element of the calling set. The resulting Set is flattened by one level.

Examples

[1, 2, 3, 4].flatMap(v => [v, v + 10])
[
  1,
  11,
  2,
  12,
  3,
  13,
  4,
  14
]

Is this article helpful? 

Tell Fauna how the article can be improved:
Visit Fauna's forums or email docs@fauna.com

Thank you for your feedback!