AllSameBy

AllSameBy[{e1,e2,},f]

tests whether all the f[ei] are the same.

AllSameBy[f]

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

Details

  • AllSameBy applies f sequentially from the first element to the last until the result is different from the ones before, i.e. it short-circuits whenever possible.
  • When {en} has length 0 or 1, True is automatically returned without f being applied.

Examples

open allclose all

Basic Examples  (1)

Test whether all numbers have the same parity:

Scope  (1)

Test if all the numbers have the same magnitude:

Applications  (1)

Check if numbers are all prime or all composite:

Properties & Relations  (1)

AllSameBy can be implemented by applying f to all elements and then checking whether the results are all the same:

The difference becomes apparent when there are side effects.

AllSameBy will cease evaluation if any variation in f[en] is found:

Whereas Map would evaluate on all elements prior to checking SameQ:

Wolfram Research (2024), AllSameBy, Wolfram Language function, https://reference.wolfram.com/language/ref/AllSameBy.html.

Text

Wolfram Research (2024), AllSameBy, Wolfram Language function, https://reference.wolfram.com/language/ref/AllSameBy.html.

CMS

Wolfram Language. 2024. "AllSameBy." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/AllSameBy.html.

APA

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

BibTeX

@misc{reference.wolfram_2024_allsameby, author="Wolfram Research", title="{AllSameBy}", year="2024", howpublished="\url{https://reference.wolfram.com/language/ref/AllSameBy.html}", note=[Accessed: 09-December-2024 ]}

BibLaTeX

@online{reference.wolfram_2024_allsameby, organization={Wolfram Research}, title={AllSameBy}, year={2024}, url={https://reference.wolfram.com/language/ref/AllSameBy.html}, note=[Accessed: 09-December-2024 ]}