Function Repository Resource:

# DeleteCasesFrom

Remove all elements from the value of a symbol that match a pattern and reset the symbol to the result

Contributed by: Ian Ford
 ResourceFunction["DeleteCasesFrom"][x,pattern] removes all elements of the value of x that match pattern and resets x to the result. ResourceFunction["DeleteCasesFrom"][x,pattern,levelspec] removes all parts of the value of x on levels specified by levelspec that match pattern and resets x to the result. ResourceFunction["DeleteCasesFrom"][x,pattern,levelspec,n] removes the first n parts of the value of x that match pattern and resets x to the result.

## Details and Options

ResourceFunction["DeleteCasesFrom"][x,pattern] is equivalent to x=DeleteCases[x,pattern].
ResourceFunction["DeleteCasesFrom"] has attribute HoldFirst.
When used on an Association, ResourceFunction["DeleteCasesFrom"] deletes elements according to their values.
With the option , you can delete heads with ResourceFunction["DeleteCasesFrom"]. Deleting the head of a particular element from x sets it equal to the result of applying FlattenAt to the value of x at that point.
ResourceFunction["DeleteCasesFrom"] uses standard level specifications.
The default value for levelspec in ResourceFunction["DeleteCasesFrom"] is {}.
A positive level n consists of all parts of the value of x specified by n indices.
A negative level -n consists of all parts of the value of x with depth n.
Level -1 consists of numbers, symbols and other objects that do not have subparts.
Level 0 corresponds to the whole expression.
ResourceFunction["DeleteCasesFrom"] traverses the parts of the value of x in a depth-first order, with leaves visited before roots.

## Examples

### Basic Examples (4)

Set s equal to a List:

 In[1]:=
 Out[1]=

Delete cases that match integers:

 In[2]:=
 Out[2]=

The value assigned to s has changed:

 In[3]:=
 Out[3]=

Delete elements from an Association:

 In[4]:=
 Out[4]=
 In[5]:=
 Out[5]=

DeleteCasesFrom can access parts of the elements of an Association:

 In[6]:=
 Out[6]=
 In[7]:=
 Out[7]=

Delete elements from a nested Association:

 In[8]:=
 Out[8]=
 In[9]:=
 Out[9]=

### Scope (2)

Delete elements matching an Association from a List:

 In[10]:=
 Out[10]=
 In[11]:=
 Out[11]=

Delete elements from a List matching a condition:

 In[12]:=
 Out[12]=
 In[13]:=
 Out[13]=
 In[14]:=
 Out[14]=

### Options (1)

Deleting the head f effectively flattens the expression:

 In[15]:=
 Out[15]=
 In[16]:=
 Out[16]=

### Possible Issues (2)

Deleting the head effectively flattens the expression:

 In[17]:=
 Out[17]=
 In[18]:=
 Out[18]=

Deleting the head in an Association removes the entry:

 In[19]:=
 Out[19]=
 In[20]:=
 Out[20]=

## Requirements

Wolfram Language 11.3 (March 2018) or above

## Version History

• 1.0.0 – 29 November 2018