Function.firstWhere()

Get the first matching accessible user-defined Function document.

Signature

Function.firstWhere(predicate: () => Boolean)): <Function> | NullFunctionDef

Function.firstWhere(predicate: (val: Function) => Boolean)): <Function> | NullFunctionDef

Description

Each user-defined function (UDF) document in a Fauna database is represented by a function object. The Function.firstWhere() method returns the first accessible function object that matches the predicate function.

Parameters

Parameter Type Required Description

predicate

Function

Yes

Anonymous function that compares values in each UDF document and returns true for matches or false for mismatches.

predicate parameters:

Parameter Type Required Description

val

Collection

UDF object to compare. If omitted, use dot notation to access function properties.

Return value

One of:

Type Description

Function

First accessible UDF document matching the predicate function. See Function document definition.

NullFunctionDef

When no UDF documents match the predicate function or all matching UDF documents are inaccessible.

Examples

Get the first UDF when at least one matching UDF document exists and is accessible:

Function.firstWhere(.name.includes('inv'))
{
  name: "inventory",
  coll: Function,
  ts: Time("2099-04-10T17:50:39.955Z"),
  role: "server",
  body: <<-END
    (name) => {
      Product.byName(name) {
        name: .name,
        description: .description,
        quantity: .quantity
      } 
    }
  END
}

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!