map()

Create a Set by applying a function to each Set value.

Lazy loading:

Yes

Signature

map(functionBody: () => B): <Set>

map(functionBody: (val: A) => B): <Set>

Description

The map() method creates a Set by applying the functionBody to each value in the Set, and returns the new Set. The source set isn’t changed.

If map() is the last value in a query, the first page of the new Set is returned.

Writes are not permitted by functionBody.

Parameters

Parameter Type Required Description

functionBody

Function

Yes

Anonymous Function that operates on a Set value and returns a value.

functionBody parameters:

Parameter Type Required Description

value

Any

Value to process.

Return value

Type Description

Set

Set resulting from the map() operation.

Examples

For all Customer documents, combine the firstName and lastName properties into a single string:

Customer.all().map(
  customer => "#{customer.firstName} #{customer.lastName}"
)
{
  data: [
    "Alice Appleseed",
    "Bob Brown",
    "Carol Clark"
  ]
}

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!