Any

Any( values )
Any( values )
Any( values )
Any( values )
any( values )
Any( values )
Any( values )

Description

The Any function tests the provided values and returns true if any of the items in values is true, otherwise it returns false.

When values is an empty Array or Set, Any returns false, because values contains no true values.

Any is a better choice for handling collections of values than the similar Or function.

The run time of Any 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 Any 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 Any evaluates. To resolve this, use Paginate to limit the set or page size.

For example, instead of:

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

use:

Any(
  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

Argument Type Definition and Requirements

values

Array or Set

A group of values to test for being true.

Returns

A Boolean indicating whether any of the items in values is true.

Examples

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

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

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

if err != nil {
	fmt.Fprintln(os.Stderr, err)
} else {
	fmt.Println(result)
}
[true true false false]
System.out.println(
    client.query(
        Arr(
            Any(Arr(Value(true), Value(true), Value(true))),
            Any(Arr(Value(false), Value(true), Value(true))),
            Any(Arr(Value(false), Value(false), Value(false))),
            Any(Arr())
        )
    ).get());
[true, true, false, false]
client.query([
  q.Any([true, true, true]),
  q.Any([false, true, true]),
  q.Any([false, false, false]),
  q.Any([]),
])
.then((ret) => console.log(ret))
.catch((err) => console.error('Error: %s', err))
[ true, true, false, false ]
result = client.query(
  [
    q.any([True, True, True]),
    q.any([False, True, True]),
    q.any([False, False, False]),
    q.any([]),
  ]
)
print(result)
[True, True, False, False]
try {
  println(Await.result(
  client.query(
    Arr(
      Any(Arr(true, true, true)),
      Any(Arr(false, true, true)),
      Any(Arr(false, false, false)),
      Any(Arr())
    )
  ),
  5.seconds
))} catch {
  case unknown: Throwable => println("Error: " + unknown.getMessage())
}
[true, true, false, false]
[
  Any([true, true, true]),
  Any([false, true, true]),
  Any([false, false, false]),
  Any([])
]
[ true, true, false, false ]

Was this article helpful?

We're sorry to hear that.
Tell us how we can improve!
Visit Fauna's Discourse forums or email docs@fauna.com

Thank you for your feedback!