Check out v4 of the Fauna CLI

v4 of the Fauna CLI is now in beta.

The new version introduces enhancements to the developer experience, including an improved authentication workflow. To get started, check out the CLI v4 quick start.

set.firstWhere()

Get the first element of a Set that matches a provided predicate.

Signature

firstWhere(predicate: (A => Boolean | Null)) => A | Null

Description

Gets the first element of the calling Set that matches a provided predicate function.

Parameters

Parameter Type Required Description

predicate

Predicate function

Yes

Anonymous predicate function that:

The method returns the first Set element for which the predicate returns true.

Return value

One of:

Type Description

Generic

First element of the Set that matches the predicate.

Null

Returned if no Set element matches the predicate or the Set is empty.

Examples

Get the first Customers document where the state property is DC:

Customer.all().firstWhere(.address.state == 'DC')
{
  id: "111",
  coll: Customer,
  ts: Time("2099-07-31T12:42:19Z"),
  cart: Order("412571379960906240"),
  orders: "hdW...",
  name: "Alice Appleseed",
  email: "alice.appleseed@example.com",
  address: {
    street: "87856 Mendota Court",
    city: "Washington",
    state: "DC",
    postalCode: "20220",
    country: "US"
  }
}

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!