Skip to content

Any ​

Whether some element of a collection satisfies a predicate.

✓ checked against that system · ! checked, with disagreements (hover a chip)Wolfram LanguageAnyTrue!
Any(xs, predicate)TrueTrue if predicatepredicate holds for at least one element of xsxs, else FalseFalse.
Any(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 ↗
InAny([1,3,5],_1⁡↦_1⁡ mod 2=0)\mathrm{Any}(\bigl\lbrack1, 3, 5\bigr\rbrack, \operatorname{\_1}↦\operatorname{\_1}\bmod2=0)OutFalse\mathrm{False}
live ↗
InAny([1,3,6],_1⁡↦_1⁡ mod 2=0)\mathrm{Any}(\bigl\lbrack1, 3, 6\bigr\rbrack, \operatorname{\_1}↦\operatorname{\_1}\bmod2=0)OutTrue\mathrm{True}

A named predicate

live ↗
InAny([4,6,7],IsPrime)\mathrm{Any}(\bigl\lbrack4, 6, 7\bigr\rbrack, \mathrm{IsPrime})OutTrue\mathrm{True}
live ↗
InAny([1,2,3],_1⁡↦_1⁡>2)\mathrm{Any}(\bigl\lbrack1, 2, 3\bigr\rbrack, \operatorname{\_1}↦\operatorname{\_1}\gt2)OutTrue\mathrm{True}

One even element suffices

live ↗
InAny([1,2,3,4,5,6],IsEven)\mathrm{Any}(\bigl\lbrack1, 2, 3, 4, 5, 6\bigr\rbrack, \mathrm{IsEven})OutTrue\mathrm{True}

No element passes

live ↗
InAny([1,3,5,7,9],IsEven)\mathrm{Any}(\bigl\lbrack1, 3, 5, 7, 9\bigr\rbrack, \mathrm{IsEven})OutFalse\mathrm{False}

Symbolic entries do not count as true, so false

live ↗
InAny([12,16,x,14,y],_1⁡↦IsTrue(_1⁡<10))\mathrm{Any}(\bigl\lbrack12, 16, x, 14, y\bigr\rbrack, \operatorname{\_1}↦\mathrm{IsTrue}(\operatorname{\_1}\lt10))OutFalse\mathrm{False}
Scope #

Without a predicate, tests the elements themselves

live ↗
InAny([False,True])\mathrm{Any}(\bigl\lbrack\mathrm{False}, \mathrm{True}\bigr\rbrack)OutTrue\mathrm{True}

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

live ↗
InAny([[1,2],[3,−4]],_1⁡↦_1⁡<0,2)\mathrm{Any}(\bigl\lbrack\bigl\lbrack1, 2\bigr\rbrack, \bigl\lbrack3, -4\bigr\rbrack\bigr\rbrack, \operatorname{\_1}↦\operatorname{\_1}\lt0, 2)OutTrue\mathrm{True}

An undecided predicate gives the disjunction of its values, as Wolfram's AnyTrue does

live ↗
InAny([a,b],f)\mathrm{Any}(\bigl\lbrack a, b\bigr\rbrack, f)Outf(a)∨f(b)f(a)∨f(b)

One True settles it, whatever else is undecided

live ↗
InAny([a,4],IsEven)\mathrm{Any}(\bigl\lbrack a, 4\bigr\rbrack, \mathrm{IsEven})OutTrue\mathrm{True}
Properties #

Always false on an empty list

live ↗
InAny([],IsEven)\mathrm{Any}(\bigl\lbrack\bigr\rbrack, \mathrm{IsEven})OutFalse\mathrm{False}

Some element passes exactly when not every element fails. See All

live ↗
InAny([1,3,5],IsEven)=¬All([1,3,5],IsOdd)\mathrm{Any}(\bigl\lbrack1, 3, 5\bigr\rbrack, \mathrm{IsEven})=¬\mathrm{All}(\bigl\lbrack1, 3, 5\bigr\rbrack, \mathrm{IsOdd})OutTrue\mathrm{True}
live ↗
InMap(LogicalExpand,[Any([x,y,z],f),¬NoneTrue([x,y,z],f)])\mathrm{Map}(\mathrm{LogicalExpand}, \bigl\lbrack\mathrm{Any}(\bigl\lbrack x, y, z\bigr\rbrack, f), ¬\mathrm{NoneTrue}(\bigl\lbrack x, y, z\bigr\rbrack, f)\bigr\rbrack)Out[f(x)∨f(y)∨f(z),f(x)∨f(y)∨f(z)]\bigl\lbrack f(x)∨f(y)∨f(z), f(x)∨f(y)∨f(z)\bigr\rbrack
About
Examples14
Checked againstWolfram Language 13 agree1 differ
CrosswalkWolfram Language

See also: All, NoneTrue