Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Evaluate expressions in turn until a given form is returned
evaluates expri in turn, returning the first result that matches pattern.
gives the value of rhs corresponding to the first value to match pattern.
gives default if no value matching pattern is found.
finds only objects that appear on levels specified by levelspec.
Find the first integer in a list without evaluating the following elements:
Expressions with side effects are evaluated once to check the returned value:
If no match is found, Missing["NotFound"] is returned:
The third argument can be used to specify the backup expression that should be evaluated if no match is found. This expression is only evaluated if necessary:
FirstMatchingValue supports replacement rules on the matching element:
Condition (/;) can be used to check additional constraints on the obtained value:
FirstMatchingValue supports standard level specifications:
When given an explicit list of elements, FirstMatchingValue returns the same element as FirstCase:
Unlike FirstCase, FirstMatchingValue does not evaluate any more expressions after a match has been found:
If you have a value that is expensive to compute and therefore worth storing for later use, FirstMatchingValue can be used to check various locations where the result could be stored and return the first successful lookup. The second evaluation of the following code will be much faster than the first:
This work is licensed under a Creative Commons Attribution 4.0 International License