Function Repository Resource:

# DropTrailingWhile

Drop elements at the end of a list so long as a criterion is fulfilled

Contributed by: Sander Huisman
 ResourceFunction["DropTrailingWhile"][list,crit] drops elements ei from the end of list, continuing so long as crit[ei] is True. ResourceFunction["DropTrailingWhile"][crit] represents an operator form of ResourceFunction["DropTrailingWhile"] that can be applied to expressions.

## Details and Options

ResourceFunction["DropTrailingWhile"] can be used on an object with any head, not necessarily List.

## Examples

### Basic Examples (2)

Drop elements from the back that are odd:

 In[1]:=
 Out[1]=

Use a pure function to drop elements from the back while they are larger than 100:

 In[2]:=
 Out[2]=

### Scope (2)

Elements of the list can be any expression:

 In[3]:=
 Out[3]=

Create an operator of DropTrailingWhile that drops trailing even numbers:

 In[4]:=
 Out[4]=

Use the operator:

 In[5]:=
 Out[5]=

### Generalizations & Extensions (2)

Use on an expression with head f:

 In[6]:=
 Out[6]=

DropTrailingWhile also works on SparseArray:

 In[7]:=
 Out[7]=

### Applications (1)

Drop trailing zeros:

 In[8]:=
 Out[8]=

### Properties and Relations (2)

DropTrailingWhile is equivalent to a combination of Drop, Reverse and LengthWhile:

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

DropTrailingWhile gives an empty list if crit[ei] is True for all elements:

 In[12]:=
 Out[12]=

### Possible Issues (1)

The list terminates for any value of crit[ei] that is not True:

 In[13]:=
 Out[13]=

SHuisman

## Requirements

Wolfram Language 11.3 (March 2018) or above

## Version History

• 1.0.0 – 26 April 2019