Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Check if all the elements of a list give the same value after applying a function
Test whether all numbers have the same parity:
| In[1]:= |
| Out[1]= |
Test if all the numbers have the same magnitude:
| In[2]:= |
| Out[2]= |
Check if numbers are all prime or all composite:
| In[3]:= |
| Out[3]= |
AllSameBy can be implemented by applying f to all elements and then checking whether the results are all the same:
| In[4]:= |
| Out[4]= |
Compare with the original function:
| In[5]:= |
| Out[5]= |
The difference becomes apparent when there are side effects:
| In[6]:= |
| Out[6]= |
Compared to the original function, the last items are untouched:
| In[7]:= |
| Out[7]= |
This work is licensed under a Creative Commons Attribution 4.0 International License