# QueryEvery

Used to iterate over a Query and test whether **every** item meets the test callback.

The function will be passed 3 arguments: the value, the index, and the Query. You can alternatively pass a Java Predicate which will only receive the 1st arg. The function should return true if the item meets the test, and false otherwise.

**Note:** This operation is a short-circuit operation, meaning it will stop iterating as soon as it finds the first item that does not meet the test condition.

## Parallel Execution

If the `parallel` argument is set to true, and no `max_threads` are sent, the filter will be executed in parallel using a ForkJoinPool with parallel streams. If `max_threads` is specified, it will create a new ForkJoinPool with the specified number of threads to run the filter in parallel, and destroy it after the operation is complete. This allows for efficient processing of large Queries, especially when the test function is computationally expensive or the Query is large.

## Method Signature

```
QueryEvery(query=[query], closure=[function:Predicate], parallel=[boolean], maxThreads=[any], virtual=[boolean])
```

### Arguments

| Argument     | Type                 | Required | Description                                                                                                                                                                                                                                                                             | Default |
| ------------ | -------------------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- |
| `query`      | `query`              | `true`   | The query to test against the callback.                                                                                                                                                                                                                                                 |         |
| `closure`    | `function:Predicate` | `true`   | The function to invoke for each item. The function will be passed 3 arguments: the row, the currentRow, the query. You can alternatively pass a Java Predicate which will only receive the 1st arg.                                                                                     |         |
| `parallel`   | `boolean`            | `false`  | Whether to run the filter in parallel. Defaults to false. If true, the filter will be run in parallel using a ForkJoinPool.                                                                                                                                                             | `false` |
| `maxThreads` | `any`                | `false`  | <p>The maximum number of threads to use when running the filter in parallel. If not passed it will use the default number of threads for the ForkJoinPool.<br>If parallel is false, this argument is ignored. If a boolean is passed it will be used as the virtual thread argument</p> |         |
| `virtual`    | `boolean`            | `false`  | Whether to use virtual threads when running the filter in parallel. Defaults to false. Ignored if parallel is false.                                                                                                                                                                    | `false` |

## Examples

### All values greater than 50

Find out if every value in the query is greater than 50

```java
<bx:script>
	data = query( foo=[
		51,
		52,
		535
	] );
	allGT50 = queryEvery( ( Any row ) => {
		return row.FOO > 50;
	} );
</bx:script>

```

Result: true

### Additional Examples

[Run Example](https://try.boxlang.io/?code=eJzFkkFPg0AQhc%2Fsr3jhYMBs7WLa2qqYqMSDhxpjPDUetjJVEgq4BZvG%2Bt%2BdBW1M05rqxc2Q3WXfDMy3r6C8SAkhbisyiyHNPbiZnpKM87HUT%2BRKuK%2FaPD5rI2Ndkkyykt%2BNIJyRcBz3rpolruTVpSE%2BjvjxEAyOlETAAd%2BeKeE8yM%2BEezPboB90t%2BmvDMUbEnpbP3CdTDfo%2B%2F11vXiAfyKialp44A7DoiYhkeoxpaHbbNFCbpKnJNMpXiwh1ya193FTlUVVHgvsc2AJy4wnpob1sQRzxNLqWjuMpp7lypMl2VIBB5Q6roPfKlu10TFO1LpB90edxVjrej%2FXY3pNvX5%2Fu64t2m2wGzSDSxNeJHnGpGybYyrnRBlLdRYjOFSilrDBGqAH9MoUPXg4zxYw%2BVx%2BLYbVdEym2b6YRWTL%2BwjP8CYcQ2VlMnievc4omUzYpQse7ETOPIhuLiSG%2BdzzOeMMysfeHnbRnoYIlPL5St%2FtvcYrM9Q%2FvfJC08KWBtccgdJUtBOiTlOi%2Bx%2BIOr9i1P0bolWDNSJ8YzTR6cxC%2BgCECzEP)

```java
people = QueryNew( "name,dob,age", "varchar,date,int", [ 
	[
		"Susi",
		CreateDate( 1970, 1, 1 ),
		0
	],
	[
		"Urs",
		CreateDate( 1995, 1, 1 ),
		0
	],
	[
		"Fred",
		CreateDate( 1960, 1, 1 ),
		0
	],
	[
		"Jim",
		CreateDate( 1988, 1, 1 ),
		0
	]
] );
Dump( var=people, label="people - original query" );
/* Output:
 *
 * | name | dob                 | age |
 * ------------------------------------
 * | Susi | 1970-01-01 00:00:00 | 0   |
 * | Urs  | 1995-01-01 00:00:00 | 0   |
 * | Fred | 1960-01-01 00:00:00 | 0   |
 * | Jim  | 1988-01-01 00:00:00 | 0   |
 */
// data validation - age between 0 and 120
valid = people.every( ( Any row, Any rowNumber, Any qryData ) => {
	return ((DateDiff( "yyyy", row.DOB, Now() ) > 0) && (DateDiff( "yyyy", row.DOB, Now() ) <= 100));
} );
dump( var=valid, label="valid - age between 0 and 120" );
/* Output: true */
// data validation - age between 40 and 50
valid = people.every( ( Any row, Any rowNumber, Any qryData ) => {
	return ((DateDiff( "yyyy", row.DOB, Now() ) > 40) && (DateDiff( "yyyy", row.DOB, Now() ) <= 50));
} );
dump( var=valid, label="valid - age between 40 and 50" );
 /* Output: false */
```

## Related

* [QueryAddColumn](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/query/queryaddcolumn)
* [QueryAddRow](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/query/queryaddrow)
* [QueryAppend](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/query/queryappend)
* [QueryClear](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/query/queryclear)
* [QueryColumnArray](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/query/querycolumnarray)
* [QueryColumnCount](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/query/querycolumncount)
* [QueryColumnData](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/query/querycolumndata)
* [QueryColumnExists](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/query/querycolumnexists)
* [QueryColumnList](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/query/querycolumnlist)
* [QueryCurrentRow](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/query/querycurrentrow)
* [QueryDeleteColumn](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/query/querydeletecolumn)
* [QueryDeleteRow](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/query/querydeleterow)
* [QueryEach](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/query/queryeach)
* [QueryFilter](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/query/queryfilter)
* [QueryGetCell](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/query/querygetcell)
* [QueryGetResult](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/query/querygetresult)
* [QueryInsertAt](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/query/queryinsertat)
* [QueryKeyExists](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/query/querykeyexists)
* [QueryMap](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/query/querymap)
* [QueryNew](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/query/querynew)
* [QueryNone](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/query/querynone)
* [QueryPrepend](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/query/queryprepend)
* [QueryRecordCount](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/query/queryrecordcount)
* [QueryRecordCount](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/query/queryrecordcount)
* [QueryReduce](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/query/queryreduce)
* [QueryRegisterFunction](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/query/queryregisterfunction)
* [QueryReverse](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/query/queryreverse)
* [QueryRowData](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/query/queryrowdata)
* [QueryRowSwap](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/query/queryrowswap)
* [QuerySetCell](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/query/querysetcell)
* [QuerySetRow](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/query/querysetrow)
* [QuerySlice](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/query/queryslice)
* [QuerySome](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/query/querysome)
* [QuerySort](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/query/querysort)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/query/queryevery.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
