Skip to content

All ​

Whether every element of a collection satisfies a predicate.

✓ checked against that system · ! checked, with disagreements (hover a chip)FungrimAllWolfram LanguageAllTrue!
All(xs, predicate)TrueTrue if predicatepredicate holds for every element of xsxs, else FalseFalse.
All(xs, predicate, level)the elements at exactly level tested instead of the top-level ones.
Typed signatures
TypePackageApplies
(collection<T>, predicate: ((T) any -> boolean)?) -> boolean where Tcombinatoricsreplaces compute-enginealways
(collection<T>, predicate: ((T) any -> boolean)?) -> boolean where Tcompute-enginealways

Domain: Collections

Examples

Basic #
live ↗
InAll([2,4,6],_1⁡↦_1⁡ mod 2=0)\mathrm{All}(\bigl\lbrack2, 4, 6\bigr\rbrack, \operatorname{\_1}↦\operatorname{\_1}\bmod2=0)OutTrue\mathrm{True}
live ↗
InAll([2,4,5],_1⁡↦_1⁡ mod 2=0)\mathrm{All}(\bigl\lbrack2, 4, 5\bigr\rbrack, \operatorname{\_1}↦\operatorname{\_1}\bmod2=0)OutFalse\mathrm{False}

A named predicate

live ↗
InAll([2,3,5,7],IsPrime)\mathrm{All}(\bigl\lbrack2, 3, 5, 7\bigr\rbrack, \mathrm{IsPrime})OutTrue\mathrm{True}
live ↗
InAll([1,2,3],_1⁡↦_1⁡>0)\mathrm{All}(\bigl\lbrack1, 2, 3\bigr\rbrack, \operatorname{\_1}↦\operatorname{\_1}\gt0)OutTrue\mathrm{True}

One odd element makes the test false

live ↗
InAll([2,3,4,6,8],IsEven)\mathrm{All}(\bigl\lbrack2, 3, 4, 6, 8\bigr\rbrack, \mathrm{IsEven})OutFalse\mathrm{False}

True when every element passes

live ↗
InAll([2,4,6,8],IsEven)\mathrm{All}(\bigl\lbrack2, 4, 6, 8\bigr\rbrack, \mathrm{IsEven})OutTrue\mathrm{True}

The element 15 already fails, so symbols don't matter

live ↗
InAll([2,6,x,4,y,15],_1⁡↦_1⁡<10)\mathrm{All}(\bigl\lbrack2, 6, x, 4, y, 15\bigr\rbrack, \operatorname{\_1}↦\operatorname{\_1}\lt10)OutFalse\mathrm{False}

Unresolved x<10x<10 is not provably true, so the test is false

live ↗
InAll([2,6,x,4,y],_1⁡↦IsTrue(_1⁡<10))\mathrm{All}(\bigl\lbrack2, 6, x, 4, y\bigr\rbrack, \operatorname{\_1}↦\mathrm{IsTrue}(\operatorname{\_1}\lt10))OutFalse\mathrm{False}
Scope #

One definite failure decides the answer, even beside a symbolic element

live ↗
InAll([1,x],IsEven)\mathrm{All}(\bigl\lbrack1, x\bigr\rbrack, \mathrm{IsEven})OutFalse\mathrm{False}

Without a predicate, tests the elements themselves

live ↗
InAll([True,True])\mathrm{All}(\bigl\lbrack\mathrm{True}, \mathrm{True}\bigr\rbrack)OutTrue\mathrm{True}

A level argument tests the elements at depth 2 of a nested list

live ↗
InAll([[1,2],[3,4]],_1⁡↦_1⁡>0,2)\mathrm{All}(\bigl\lbrack\bigl\lbrack1, 2\bigr\rbrack, \bigl\lbrack3, 4\bigr\rbrack\bigr\rbrack, \operatorname{\_1}↦\operatorname{\_1}\gt0, 2)OutTrue\mathrm{True}

An undecided predicate gives the conjunction of its values, as Wolfram's AllTrue does

live ↗
InAll([a,b],f)\mathrm{All}(\bigl\lbrack a, b\bigr\rbrack, f)Outf(a)∧f(b)f(a)∧f(b)

One False settles it, whatever else is undecided

live ↗
InAll([a,3],IsEven)\mathrm{All}(\bigl\lbrack a, 3\bigr\rbrack, \mathrm{IsEven})OutFalse\mathrm{False}
Properties #

Vacuously true on an empty list

live ↗
InAll([],IsEven)\mathrm{All}(\bigl\lbrack\bigr\rbrack, \mathrm{IsEven})OutTrue\mathrm{True}
About
Examples14
Checked againstWolfram Language 13 agree1 differ
CrosswalkFungrimWolfram Language

See also: Any, NoneTrue