Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Conveniently get both the first and remaining elements
ResourceFunction["FirstRest"][expr] returns a list containing the first element and the remaining elements of expr. | |
ResourceFunction["FirstRest"][expr,def] returns the first and remaining elements, or def otherwise, and the rest of the list. |
Take the First and the Rest of a list:
| In[1]:= |
| Out[1]= |
| In[2]:= |
| Out[2]= |
Apply FirstRest to objects like SparseArray or NumericArray:
| In[3]:= |
| Out[3]= |
FirstRest is useful for starting a fold-like operation:
| In[4]:= |
| Out[4]= |
FirstRest works on arbitrary expressions:
| In[5]:= |
| Out[5]= |
FirstRest will return only the first value (not key) when given an Association:
| In[6]:= |
| Out[6]= |
FirstRest returns an empty list if First fails and no default is provided:
| In[7]:= |
| Out[7]= |
| In[8]:= |
| Out[8]= |
This work is licensed under a Creative Commons Attribution 4.0 International License