map()

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

Signature

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

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

Description

The map() method creates a Set by applying the lambda function to each value in the Set, and returns the new Set.

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

The source set isn’t changed.

Parameters

Parameter Type Required Description

lambda

Function

Yes

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

lambda parameters:

Parameter Type Required Description

value

Any

Value to process.

Return value

Type Description

Set

Created Set.

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!