Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
PositionedCases
Find positions and values within an expression matching a pattern
ResourceFunction["PositionedCases"][expr,pattern] gives an Association mapping positions of objects in expr matching pattern to their values. | |
ResourceFunction["PositionedCases"][expr,pattern,levelspec] finds only positions and values that appear on the levels specified by levelspec. | |
ResourceFunction["PositionedCases"][expr,pattern,levelspec,n] gives the positions and values of the first n objects found. | |
ResourceFunction["PositionedCases"][pattern] represents an operator form. |
Examples
Basic Examples (3)
Get positions of integers in an expression along with the integer values:
| In[1]:= |
| Out[1]= |
Find values in an Association:
| In[2]:= | ![]() |
| Out[2]= | ![]() |
Create an operator:
| In[3]:= |
| Out[3]= |
Use it:
| In[4]:= |
| Out[4]= |
Scope (3)
Use a pattern test and a level spec:
| In[5]:= |
| Out[5]= |
Also limit the number of results:
| In[6]:= |
| Out[6]= |
Up to the first two levels:
| In[7]:= |
| Out[7]= |
Options (1)
Use the Heads option to control whether to include heads of expressions:
| In[8]:= |
| Out[8]= |
| In[9]:= |
| Out[9]= |
Applications (2)
Retrieve a dataset:
| In[10]:= |
| Out[10]= | ![]() |
Find positions and values in given range:
| In[11]:= |
| Out[11]= |
Version History
- 1.0.0 – 27 February 2020
Related Resources
Related Symbols
License Information
This work is licensed under a Creative Commons Attribution 4.0 International License
![ResourceFunction[
"PositionedCases"][<|
"schedule" -> <|
"dates" -> <|"today" -> Today, "yesterday" -> Yesterday|>|>|>, _DateObject]](https://cdn.statically.io/img/www.wolframcloud.com/obj/resourcesystem/images/2fd/2fd1e342-1d76-448a-aabb-6ef0d9fbf868/596cfd4817581491.png)

