AnyTrue

AnyTrue[{e1,e2,},test]

yields True if test[ei] is True for any of the ei.

AnyTrue[expr,test,level]

tests parts of expr at level level.

AnyTrue[test]

represents an operator form of AnyTrue that can be applied to an expression.

Details

  • AnyTrue[expr,test] and AnyTrue[expr,test,level] only evaluate as many test[ei] as are necessary to determine the result.
  • AnyTrue[list,test] is equivalent to AnyTrue[list,test,1].
  • AnyTrue[test][list] is equivalent to AnyTrue[list,test].

Examples

open allclose all

Basic Examples  (4)

Check if any element of a list satisfies a condition:

Check if any element of a matrix satisfies a condition:

Check if any value of an association satisfies a condition:

A symbolic result may be returned:

TrueQ may be used to avoid getting a symbolic result:

Scope  (3)

AnyTrue may be applied to expressions with any head:

AnyTrue can operate on ragged expressions:

By default, AnyTrue operates at level 1:

Properties & Relations  (4)

Compose the predicate with TrueQ to make the predicate stronger:

AnyTrue[list,f] is equivalent to !NoneTrue[list,f]:

AnyTrue[list,f] works efficiently on sparse vectors:

AnyTrue[list,test] checks the parts of list in order, stopping as soon as test returns True:

Possible Issues  (1)

A symbolic result may be returned:

Wolfram Research (2014), AnyTrue, Wolfram Language function, https://reference.wolfram.com/language/ref/AnyTrue.html (updated 2015).

Text

Wolfram Research (2014), AnyTrue, Wolfram Language function, https://reference.wolfram.com/language/ref/AnyTrue.html (updated 2015).

CMS

Wolfram Language. 2014. "AnyTrue." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2015. https://reference.wolfram.com/language/ref/AnyTrue.html.

APA

Wolfram Language. (2014). AnyTrue. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/AnyTrue.html

BibTeX

@misc{reference.wolfram_2024_anytrue, author="Wolfram Research", title="{AnyTrue}", year="2015", howpublished="\url{https://reference.wolfram.com/language/ref/AnyTrue.html}", note=[Accessed: 22-November-2024 ]}

BibLaTeX

@online{reference.wolfram_2024_anytrue, organization={Wolfram Research}, title={AnyTrue}, year={2015}, url={https://reference.wolfram.com/language/ref/AnyTrue.html}, note=[Accessed: 22-November-2024 ]}