# 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="compose" %}
[compose](https://antonioru.gitbook.io/deep-waters/composition/compose)
{% endcontent-ref %}

{% content-ref url="or" %}
[or](https://antonioru.gitbook.io/deep-waters/composition/or)
{% endcontent-ref %}

{% content-ref url="not" %}
[not](https://antonioru.gitbook.io/deep-waters/composition/not)
{% endcontent-ref %}
