All

All( values )
All( values )
All( values )
All( values )
all( values )
All( values )

Description

The All function tests the provided values and returns true if all of the items in values are true, otherwise it returns false.

When values is an empty Array or Set, All returns true, because values itself is set.

All is a better choice for handling collections of values than the similar And function.

The run time of All is dependent on the number of elements in the underlying set or page — it’s linear, or O(n). For very large sets or pages, executing All might result in a query timeout error, or "width" error.

For query "width" errors, the underlying set or page involves more than 100K items. This can happen when using a set function, such as Difference, where more than 100K items need to be considered to produce the set that All evaluates. To resolve this, use Paginate to limit the set or page size.

For example, instead of:

All(
  Difference(
    Match(Index("Index1"), "term1"),
    Match(Index("Index2"), "term2")
  )
)

use:

All(
  Paginate(
    Difference(
      Match(Index("Index1"), "term1"),
      Match(Index("Index2"), "term2")
    ),
    { size: 10000 }
  )
)

This does mean that if the entire set must be evaluated to arrive at the correct result, you would have to page through the Paginate results.

For query timeout errors, you may specify a larger query timeout via the driver that you are using.

Parameters

Parameter Type Definition and Requirements

values

Array or Set

A group of values to test for being true.

Returns

A Boolean indicating whether all of the items in values are true.

Examples

The following query uses All multiple times to demonstrate how the function evaluates several groups of values:

try
{
    Value result = await client.Query(
        Arr(
            All(Arr(true, true, true)),
            All(Arr(false, true, true)),
            All(Arr())
        )
    );

    Console.WriteLine(result);
}
catch (Exception e)
{
    Console.WriteLine($"ERROR: {e.Message}");
}
Arr(BooleanV(True), BooleanV(False), BooleanV(True))
result, err := client.Query(
	f.Arr{
		f.All(f.Arr{true, true, true}),
		f.All(f.Arr{false, true, true}),
		f.All(f.Arr{}),
	})

if err != nil {
	fmt.Fprintln(os.Stderr, err)
} else {
	fmt.Println(result)
}
[true false true]
System.out.println(
    client.query(
        Arr(
            All(Arr(Value(true), Value(true), Value(true))),
            All(Arr(Value(false), Value(true), Value(true))),
            All(Arr())
        )
    ).get());
[true, false, true]
client.query([
  q.All([true, true, true]),
  q.All([false, true, true]),
  q.All([]),
])
.then((ret) => console.log(ret))
.catch((err) => console.error(
  'Error: [%s] %s: %s',
  err.name,
  err.message,
  err.errors()[0].description,
))
[ true, false, true ]
result = client.query(
  [
    q.all([True, True, True]),
    q.all([False, True, True]),
    q.all([]),
  ]
)
print(result)
[True, False, True]
[
  All([true, true, true]),
  All([false, true, true]),
  All([])
]
[ true, false, true ]
Query metrics:
  •    bytesIn:  63

  •   bytesOut:  30

  • computeOps:   1

  •    readOps:   0

  •   writeOps:   0

  •  readBytes:   0

  • writeBytes:   0

  •  queryTime: 4ms

  •    retries:   0

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!