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.every()

Test if every element of a Set matches a provided predicate.

Signature

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

Description

Tests if every element of the calling Set matches a provided predicate function.

Eager loading

This method uses eager loading and requires a read of each document in the calling Set. For large Sets, this may result in poor performance and high costs.

Performance hint: full_set_read

Queries that call this method on a document Set emit a performance hint, if enabled. For example, the following query:

// Use `every()` to get all products with
// more than 20 items in stock.
Product.all().every(.stock > 20)

Emits the following hint:

performance_hint: full_set_read - Using every() causes the full set to be read. See https://docs.fauna.com/performance_hint/full_set_read.
at *query*:3:20
  |
3 | Product.all().every(.stock > 20)
  |                    ^^^^^^^^^^^^^
  |

To address the hint, use set.take() to explicitly limit the size of the calling Set to fewer than 100 documents:

// Limit the doc Set's size using `take()`
Product.all().take(20).every(.stock > 20)

This applies even if the original, unbounded Set contains fewer than 100 documents.

Alternatively, you can rewrite the query to avoid calling the method.

Parameters

Parameter Type Required Description

predicate

Predicate function

Yes

Anonymous predicate function that:

The method returns true if the predicate is true for every element in the Set.

Return value

Type Description

Boolean

If true, the predicate evaluates to true for every element of the Set. Otherwise, false.

Examples

// `toSet()` converts an Array to a Set.
let set = [1, -2, 3].toSet()
set.every(v => v > 0)
false

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!