Function Repository Resource:

# RotateLeftUntil

Cycle the elements of a list to the left until a criterion is satisfied

Contributed by: Sander Huisman
 ResourceFunction["RotateLeftUntil"][expr,crit] cycles the elements in expr positions to the left until the first element satisfies crit. ResourceFunction["RotateLeftUntil"][expr,crit,n] cycles the elements in expr positions until crit has been satisfied n times. ResourceFunction["RotateLeftUntil"][expr,crit,n,m] cycles the elements in expr positions until crit has been satisfied n times with at most m iterations.

## Details and Options

ResourceFunction["RotateLeftUntil"] is generally used to bring a certain element to the front.
The default value of n is 1.
When n is 0, the original expr is returned.
m is by default set to n×Length[expr].
\$Failed is returned if n fulfillments cannot be found in m iterations.

## Examples

### Basic Examples (2)

Put the element "e" in front:

 In[1]:=
 Out[1]=

Rotate until the fourth prime is in front:

 In[2]:=
 Out[2]=

### Scope (3)

Rotate until the first 5 is in front:

 In[3]:=
 Out[3]=

Rotate until a value greater than or equal to 4 has been seen three times:

 In[4]:=
 Out[4]=

Find the seventh occurrence of a value between 5 and 7, with a maximum of 100 iterations:

 In[5]:=
 Out[5]=

### Applications (1)

Rotate the letters until a capital letter is at the front:

 In[6]:=
 Out[6]=

### Properties and Relations (1)

RotateLeftUntil is related to RotateLeft and Position:

 In[7]:=
 Out[8]=

### Possible Issues (2)

If the condition is not fulfilled within a cycle, \$Failed is returned:

 In[9]:=
 Out[9]=

For crit that change, more than n cycles might be needed:

 In[10]:=
 Out[10]=

Increase the maximum number of iterations:

 In[11]:=
 Out[11]=

SHuisman

## Version History

• 1.0.0 – 29 July 2019