set.lastWhere()

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

Signature

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

Description

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

Parameters

Parameter Type Required Description

predicate

Predicate function

Yes

Anonymous predicate function that:

  • Accepts a Set element as its only argument. Supports shorthand-syntax for objects and documents.

  • Returns a Boolean value.

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

Return value

One of:

Type Description

Generic

Last element of the Set that matches the predicate.

Null

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

Examples

// `toSet()` converts an Array to a Set.
let set = [1, 2, 3, 4].toSet()
set.lastWhere(v => v > 2)
4

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!