# StructSome

Used to iterate over a struct and test whether **ANY** items meet the test callback.

The function will be passed 3 arguments: the key, the value, and the struct. You can alternatively pass a Java BiPredicate which will only receive the first 2 args. 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 meets 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. Please note that this may not be the most efficient way to iterate, as it will create a new ForkJoinPool for each invocation of the BIF. You may want to consider using a shared ForkJoinPool for better performance.

## Method Signature

```
StructSome(struct=[structloose], callback=[function:BiPredicate], parallel=[boolean], maxThreads=[any], virtual=[boolean])
```

### Arguments

| Argument     | Type                   | Required | Description                                                                                                                                                                                                                                                                                              | Default |
| ------------ | ---------------------- | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- |
| `struct`     | `struct`               | `true`   | The target struct to test                                                                                                                                                                                                                                                                                |         |
| `callback`   | `function:BiPredicate` | `true`   | The function used to test. The function will be passed 3 arguments: the key, the value, the struct. You can alternatively pass a Java BiPredicate which will only receive the first 2 args.                                                                                                              |         |
| `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 parallel is true and maxThreads is not passed, it will use the common ForkJoinPool.</p> |         |
| `virtual`    | `boolean`              | `false`  | Whether to use a virtual thread for each task when running in parallel. Defaults to false. Ignored if parallel is false.                                                                                                                                                                                 | `false` |

## Examples

### The simple StructSome example

Here we have simple example about structsome function.

```java
<bx:script>
	struct = {
		"Name" : "Raja",
		"age" : 20,
		"mark" : 80
	};
	result = structSome( struct, ( Any key, Any value ) => {
		return key == "Name";
	} );
	writeOutput( (result ? "" : "No") & " Key Exists." );
</bx:script>

```

Result: Key Exists.

### The structSome member function example

Here we have simple example about structsome as member function.

```java
<bx:script>
	struct = {
		"Name" : "Raja",
		"age" : 20,
		"mark" : 80
	};
	result = struct.some( ( Any key, Any value ) => {
		return key == "average";
	} );
	writeOutput( (result ? "" : "No") & " Key Exists." );
</bx:script>

```

Result: No Key Exists.

### Additional Examples

[Run Example](https://try.boxlang.io/?code=eJx1jb0KAjEQhOvsU2yZgyConSHCIRbWin3UtTF3J%2FkRjiPv7uZylWA3s9%2FOTIhocEIQa9zhBEK0h8vpemQTfSIQWYHY%2FKKndWFh238MsgZPIbkyELjsHs9DR5K1QoltP%2BKLRjWLj3WJsEGzL12P1L0l37yZ7wqdvZEz%2FI2NBuEpJt%2FXzKrOasgF1eAyyv4Lv8A9hg%3D%3D)

```java
st = { 
	1 : {
		ACTIVE : true
	},
	2 : {
		ACTIVE : false
	},
	3 : {
		ACTIVE : false
	}
};
result = structSome( st, ( Any key, Any value ) => {
	dump( var=value, label=key );
	return value.ACTIVE;
} );
dump( result );

```

## Related

* [StructAppend](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/struct/structappend)
* [StructClear](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/struct/structclear)
* [StructCopy](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/struct/structcopy)
* [StructDelete](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/struct/structdelete)
* [StructEach](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/struct/structeach)
* [StructEquals](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/struct/structequals)
* [StructEvery](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/struct/structevery)
* [StructFilter](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/struct/structfilter)
* [StructFind](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/struct/structfind)
* [StructFindKey](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/struct/structfindkey)
* [StructFindValue](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/struct/structfindvalue)
* [StructGet](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/struct/structget)
* [StructGetMetadata](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/struct/structgetmetadata)
* [StructInsert](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/struct/structinsert)
* [StructIsCaseSensitive](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/struct/structiscasesensitive)
* [StructIsOrdered](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/struct/structisordered)
* [StructKeyArray](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/struct/structkeyarray)
* [StructKeyExists](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/struct/structkeyexists)
* [StructKeyList](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/struct/structkeylist)
* [StructKeyTranslate](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/struct/structkeytranslate)
* [StructMap](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/struct/structmap)
* [StructNew](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/struct/structnew)
* [StructNone](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/struct/structnone)
* [StructReduce](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/struct/structreduce)
* [StructSort](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/struct/structsort)
* [StructToQueryString](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/struct/structtoquerystring)
* [StructToSorted](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/struct/structtosorted)
* [StructUpdate](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/struct/structupdate)
* [StructValueArray](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/struct/structvaluearray)
