> For the complete documentation index, see [llms.txt](https://antonioru.gitbook.io/deep-waters/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://antonioru.gitbook.io/deep-waters/composition/when.md).

# when

Takes two validators, the $$condition$$ validator and the $$fn$$ validator, then returns a new function receiving a value $$v$$ (of any type) and execute the $$fn$$ validator only when the $$condition(v)$$ returns true.

It is largely used within the library itself to evaluate certain conditions:

{% code title="contains.js" %}

```javascript
/* Part of the contains validator */


const contains = (value) => compose(
  when(isString, (string) => string.includes(value)),
  when(Array.isArray, arrayContains(value)),
  when(not(or(isString, Array.isArray)), stubFalse),
);
```

{% endcode %}

#### Related validators

{% content-ref url="/pages/-M6UnOFUFTxUoRqZRTcT" %}
[compose](/deep-waters/composition/compose.md)
{% endcontent-ref %}

{% content-ref url="/pages/-M6UnXFlU6IeRdIBsRG0" %}
[or](/deep-waters/composition/or.md)
{% endcontent-ref %}

{% content-ref url="/pages/-M6UnanTnzxPY5GLxnUW" %}
[not](/deep-waters/composition/not.md)
{% endcontent-ref %}
