set.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.

Iterator methods

FQL provides several methods for iterating over a set. set.forEach() and set.map() are similar but used for different purposes:

Method Primary use Notes

Perform in-place writes on set elements.

Doesn’t return a value.

Return a new set with projected or transformed elements.

Can’t perform writes.

Similar to set.map(), but flattens the resulting set by one level.

Can’t perform writes.

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 address.city and address.state properties into a single string:

Customer.all().map(
  customer => "#{customer.address.city}, #{customer.address.state}"
)
{
  data: [
    "Washington, DC",
    "Washington, DC",
    "Washington, DC"
  ]
}

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!