# Rust Iterator Cheat Sheet

To-do:

• Improve formatting.
• Try to fix display bugs (lines through cells).
• Add sorting... somehow

How you can help:

I need feedback on what does and doesn't work. Can you understand the summaries? Do they mesh with how you perceive the methods in question work? What other information could/should be included?

If you have any corrections or suggestions, you can file them on the GitHub repository. The canonical source for this page is src/itercheat/itercheat.html.

This summarises the iterator-related methods defined by the following Rust libraries:

Additional filtering options:

• : show unstable methods.

This is intended to be used in one of a few ways:

1. You know what an iterator method is called, but you want a quick summary of what it does.
2. You know what you want to do with an iterator, but not what it's called.
3. You just want to browse through a summary of the available methods because you're bored.

To keep the summary as compact as possible, various bits of notation and convention are used. An incomplete list is:

• Most iterator methods take their first input by-value; those that don't are marked with a &mut$\text{&mut}$ out the front of their first argument.

• Elements are underlined to indicate that the method will not compute those elements during the course of its own evaluation.

• {}$\{\ldots\}$ is used to represent a lazily computed sequence; i.e. an iterator.

• {}:{T}$\{\ldots\}:\{T\}$ indicates an iterator where each element is of type T.

• a$a$ and b$b$ are used as input sequences (with subscripted letters denoting individual elements).

• c$c$ is used to represent the output sequence in cases where there is no direct mapping of input elements to output elements.

• i$i$, j$j$, and k$k$ are used to denote specific, but arbitrary, points within sequences.

• n$n$, m$m$, and l$l$ are used to denote the length of different sequences.

• []$[\ldots]$ is used to represent a collection of arbitrary type. Typically, the exact type is inferred from context, and can be anything that implements the FromIterator trait.

• f$f$ is a function which transforms elements.

• p$p$ is a predicate which determines some logical property of elements.

• $\circ$ is an arbitrary binary function.

• wh.$\text{wh.}$ is an abbreviation for "where".

## Generators

Lib Function Input Output
Std repeat$\text{repeat}$ a$a$ {a,a,}$\{a, a, \ldots\}$
IT RepeatCall::new$\text{RepeatCall::new}$ f:()T$f: () \rightarrow T$ {f(),f(),}$\{f(), f(), \ldots\}$

## Sequences

Lib Method Input Output
IT batching$\text{batching}$ {a0,,ai,,}:{T}$\{\underbrace{a_0, \ldots}, \underbrace{a_i,\ldots}, \ldots\}:\{T\}$, batch:&mut {T}U$batch : \text{&mut }\{T\} \rightarrow U$ {c0batch({a0,}),c1batch({ai,}),}:{U}$\{\underbrace{c_0}_{batch(\{a_0, \ldots\})}, \underbrace{c_1}_{batch(\{a_i, \ldots\})}, \ldots\}:\{U\}$
IT cartesian_product$\text{cartesian_product}$ {a0,a1,,an1}$\{a_0, a_1, \ldots, a_{n-1}\}$, {b0,b1,,bm1}$\{b_0, b_1, \ldots, b_{m-1}\}$ {(a0,b0),(a0,b1),,(a0,bm1),  (a1,b0),(a1,b1),,(a1,bm1)  ,  (an1,b0),(an1,b1),,(an1,bm1)}$\{(a_0, b_0), (a_0, b_1), \ldots, (a_0, b_{m-1}),\\~~ (a_1, b_0), (a_1, b_1), \ldots, (a_1, b_{m-1})\\~~ \ldots,\\~~ (a_{n-1}, b_0), (a_{n-1}, b_1), \ldots, (a_{n-1}, b_{m-1})\}$
Std chain$\text{chain}$ {a0,,an1}$\{a_0, \ldots, a_{n-1}\}$, {b0,,bm1}$\{b_0, \ldots, b_{m-1}\}$ {a0,,an1,b0,,bm1}$\{a_0, \ldots, a_{n-1}, b_0, \ldots, b_{m-1}\}$
IT coalesce$\text{coalesce}$ {a0,a1,a2,}$\{a_0, a_1, a_2, \ldots\}$ f:(T,T)Ok(T) | Err((T,T))$f : (T,T) \rightarrow \text{Ok}(T) ~|~ \text{Err}((T, T))$ oror{x0,}{a0,x1,}{a0,a′′1,}wh.wh.wh.{f(a0,a1)=Ok(x0),f(a0,a1)=Err((a0,a1)),f(a1,a2)=Ok(x1),f(a0,a1)=Err((a0,a1)),f(a1,a2)=Err(a′′1,a2),$\begin{array}{llcl} & \{x_0, \ldots\} &\text{wh.}& \left\{\begin{array}{l} f(a_0, a_1) = \text{Ok}(x_0), \\ \ldots \end{array}\right. \\ \text{or} & \{a'_0, x_1, \ldots\} &\text{wh.}& \left\{\begin{array}{l} f(a_0, a_1) = \text{Err}((a'_0, a'_1)), \\ f(a'_1, a_2) = \text{Ok}(x_1), \\ \ldots \end{array}\right. \\ \text{or} & \{a'_0, a''_1, \ldots\} &\text{wh.}& \left\{\begin{array}{l} f(a_0, a_1) = \text{Err}((a'_0, a'_1)), \\ f(a'_1, a_2) = \text{Err}(a''_1, a'_2), \\ \ldots \end{array}\right. \end{array}$
Std collect$\text{collect}$ {a0,}$\{a_0, \ldots\}$ [a0,]$[a_0, \ldots]$
IT collect_vec$\text{collect_vec}$ {a0,}$\{a_0, \ldots\}$ [a0,]:VecT$[a_0, \ldots] : \text{Vec}\langle T\rangle$
IT combinations$\text{combinations}$ {a0,a1,a2,,an2,an1}$\{a_0, a_1, a_2, \ldots, a_{n-2}, a_{n-1}\}$ {(a0,a1),(a0,a2),,(a0,an2),(a0,an1),  (a1,a2),,(a1,an2),(a1,an1),  ,  (an2,an1)}$\{ (a_0, a_1), (a_0, a_2), \ldots, (a_0, a_{n-2}), (a_0, a_{n-1}),\\~~ (a_1, a_2), \ldots, (a_1, a_{n-2}), (a_1, a_{n-1}),\\~~ \ldots,\\~~ (a_{n-2}, a_{n-1})\}$
Std cycle$\text{cycle}$ {a0,,an1}$\{a_0, \ldots, a_{n-1}\}$ {a0,,an1,a0,,an1,}$\{a_0, \ldots, a_{n-1}, a_0, \ldots, a_{n-1}, \ldots\}$
IT dedup$\text{dedup}$ {a0,a0,,a1,a1,,}$\{\underbrace{a_0, a_0, \ldots}, \underbrace{a_1, a_1, \ldots}, \ldots\}$ {a0,a1,}$\{a_0, a_1, \ldots\}$
IT dropping$\text{dropping}$ {a0,,ai1consumed,ai,}$\{\underbrace{a_0, \ldots, a_{i-1}}_{\text{consumed}}, a_i, \ldots\}$ i wh. i<n$i \text{ wh. } i \lt n$ {ai,}$\{a_i, \ldots\}$ (consumes a0ai1$a_0 \ldots a_{i-1}$ immediately)
{a0,,an1consumed}$\{\underbrace{a_0, \ldots, a_{n-1}}_{\text{consumed}}\}$ i wh. in$i \text{ wh. } i \ge n$ {}$\{\}$ (consumes a0an1$a_0 \ldots a_{n-1}$ immediately)
IT dropping_back$\text{dropping_back}$ {a0,,ani1,ani,,an1consumed}$\{a_0, \ldots, a_{n-i-1}, \underbrace{a_{n-i}, \ldots, a_{n-1}}_{\text{consumed}}\}$ i wh. i<n$i \text{ wh. } i \lt n$ {a0,,ani1}$\{a_0, \ldots, a_{n-i-1}\}$ (consumes anian$a_{n-i} \ldots a_n$ immediately)
{a0,,an1consumed}$\{\underbrace{a_0, \ldots, a_{n-1}}_{\text{consumed}}\}$ i wh. in$i \text{ wh. } i \ge n$ {}$\{\}$ (consumes a0an$a_0 \ldots a_n$ immediately)
Std enumerate$\text{enumerate}$ {a0,a1,}$\{a_0, a_1, \ldots\}$ {(0,a0),(1,a1),}$\{(0, a_0), (1, a_1), \ldots\}$
Std filter$\text{filter}$ {a0,a1,}$\{a_0, a_1, \ldots\}$, p:&Tbool$p : \&T \rightarrow \text{bool}$ {ai for all i wh. p(&ai)}$\{a_i \text{ for all } i \text{ wh. } p(\&a_i)\}$
Std filter_map$\text{filter_map}$ {a0,a1,}$\{a_0, a_1, \ldots\}$, f:TSome(U) | None$f : T \rightarrow \text{Some}(U) ~|~ \text{None}$ {xi for all i where f(ai)=Some(xi)}$\{x_i \text{ for all } i \text { where } f(a_i) = \text{Some}(x_i)\}$
Std flat_map$\text{flat_map}$ {a0,a1,}$\{a_0, a_1, \ldots\}$, f:T{U}$f : T \rightarrow \{U\}$ {x0,x1,x=f(a0),y0,y1,y=f(a1),}$\{\underbrace{x_0, x_1, \ldots}_{x = f(a_0)}, \underbrace{y_0, y_1, \ldots}_{y = f(a_1)}, \ldots\}$
IT group_by$\text{group_by}$ {a0,,ai1g(ax)=g0,ai,,aj1g(ay)=g1g0,aj,,ak1g(az)=g2g1,}$\{\underbrace{a_0, \ldots, a_{i-1}}_{g(a_x) = g_0}, \underbrace{a_i, \ldots, a_{j-1}}_{g(a_y) = g_1 \ne g_0}, \underbrace{a_j, \ldots, a_{k-1}}_{g(a_z) = g_2 \ne g_1}, \ldots\}$, g:&TG$g : \&T \rightarrow G$ {(g0,[a0,,ai1]),  (g1,[ai,,aj1]),  (g2,[aj,,ak1]),}$\{ (g_0, [a_0, \ldots, a_{i-1}]),\\~~ (g_1, [a_i, \ldots, a_{j-1}]),\\~~ (g_2, [a_j, \ldots, a_{k-1}]), \ldots \}$
IT group_by_lazy$\text{group_by_lazy}$ {a0,,ai1g(ax)=g0,ai,,aj1g(ay)=g1g0,aj,,ak1g(az)=g2g1,}$\{\underbrace{a_0, \ldots, a_{i-1}}_{g(a_x) = g_0}, \underbrace{a_i, \ldots, a_{j-1}}_{g(a_y) = g_1 \ne g_0}, \underbrace{a_j, \ldots, a_{k-1}}_{g(a_z) = g_2 \ne g_1}, \ldots\}$, g:&TG$g : \&T \rightarrow G$ {(g0,{a0,,ai1}),  (g1,{ai,,aj1}),  (g2,{aj,,ak1}),}$\{ (g_0, \{a_0, \ldots, a_{i-1}\}),\\~~ (g_1, \{a_i, \ldots, a_{j-1}\}),\\~~ (g_2, \{a_j, \ldots, a_{k-1}\}), \ldots \}$
IT interleave$\text{interleave}$ {a0,a1,,ai1,ai,}$\{a_0, a_1, \ldots, a_{i-1}, a_i, \ldots\}$ {b0,b1,,bi1}$\{b_0, b_1, \ldots, b_{i-1}\}$ {a0,b0,a1,b1,,ai1,bi1,ai,}$\{a_0, b_0, a_1, b_1, \ldots, a_{i-1}, b_{i-1}, a_i, \ldots\}$
{a0,a1,,ai1}$\{a_0, a_1, \ldots, a_{i-1}\}$ {b0,b1,,bi1}$\{b_0, b_1, \ldots, b_{i-1}\}$ {a0,b0,a1,b1,,ai1,bi1}$\{a_0, b_0, a_1, b_1, \ldots, a_{i-1}, b_{i-1}\}$
{a0,a1,,ai1}$\{a_0, a_1, \ldots, a_{i-1}\}$ {b0,b1,,bi1,bi,}$\{b_0, b_1, \ldots, b_{i-1}, b_i, \ldots\}$ {a0,b0,a1,b1,,ai1,bi1,bi,}$\{a_0, b_0, a_1, b_1, \ldots, a_{i-1}, b_{i-1}, b_i, \ldots\}$
IT interleave_shortest$\text{interleave_shortest}$ {a0,a1,,ai1,ai,}$\{a_0, a_1, \ldots, a_{i-1}, a_i, \underline{\ldots}\}$ {b0,b1,,bi1}$\{b_0, b_1, \ldots, b_{i-1}\}$ {a0,b0,a1,b1,,ai1,bi1,ai}$\{a_0, b_0, a_1, b_1, \ldots, a_{i-1}, b_{i-1}, a_i\}$
{a0,a1,,ai1}$\{a_0, a_1, \ldots, a_{i-1}\}$ {b0,b1,,bi1,bi,}$\{b_0, b_1, \ldots, b_{i-1}, \underline{b_i, \ldots}\}$ {a0,b0,a1,b1,,ai1,bi1}$\{a_0, b_0, a_1, b_1, \ldots, a_{i-1}, b_{i-1}\}$
IT intersperse$\text{intersperse}$ {a0,a1,,an1}$\{a_0, a_1, \ldots, a_{n-1}\}$ b$b$ {a0,b,a1,b,,b,an1}$\{a_0, b, a_1, b, \ldots, b, a_{n-1}\}$
Std map$\text{map}$ {a0,a1,}$\{a_0, a_1, \ldots\}$, f:TU$f : T \rightarrow U$ {f(a0),f(a1),}$\{f(a_0), f(a_1), \ldots\}$
IT map_fn$\text{map_fn}$ {a0,a1,}$\{a_0, a_1, \ldots\}$, f:fn(T)U$f : \text{fn}(T) \rightarrow U$ {f(a0),f(a1),}$\{f(a_0), f(a_1), \ldots\}$
IT mend_slices$\text{mend_slices}$ {&[x0,,xi1],&[xi,,xn1],  &[y0,,ym1],  &[z0,,zl1],}$\{ \&[x_0, \ldots, x_{i-1}], \&[x_i, \ldots, x_{n-1}],\\~~ \&[y_0, \ldots, y_{m-1}],\\~~ \&[z_0, \ldots, z_{l-1}], \ldots \}$ {&[x0,,xi1,xi,,xn1],  &[y0,,ym1],  &[z0,,zl1],}$\{ \&[x_0, \ldots, x_{i-1}, x_i, \ldots, x_{n-1}],\\~~ \&[y_0, \ldots, y_{m-1}],\\~~ \&[z_0, \ldots, z_{l-1}], \ldots \}$
IT merge$\text{merge}$ {a0,a1,} wh. a0a1$\{a_0, a_1, \ldots\} \text{ wh. } a_0 \le a_1 \le \ldots$, {b0,b1,} wh. b0b1$\{b_0, b_1, \ldots\} \text{ wh. } b_0 \le b_1 \le \ldots$ {c0,c1,} wh. c0c1,ac,bc$\{c_0, c_1, \ldots\} \text{ wh. } c_0 \le c_1 \le \ldots, a \subseteq c, b \subseteq c$
IT merge_by$\text{merge_by}$ {a0,a1,} wh. a0a1$\{a_0, a_1, \ldots\} \text{ wh. } a_0 \circ a_1 \circ \ldots$, {b0,b1,} wh. b0b1$\{b_0, b_1, \ldots\} \text{ wh. } b_0 \circ b_1 \circ \ldots$, :(&T,&T)>Ordering${}\circ{} : (\&T,\&T) -> \text{Ordering}$ {c0,c1,} wh. c0c1,ac,bc$\{c_0, c_1, \ldots\} \text{ wh. } c_0 \circ c_1 \circ \ldots, a \subseteq c, b \subseteq c$
Std partition$\text{partition}$ {a0,a1,}$\{a_0, a_1, \ldots\}$ f:&Tbool$f: \text{&}T \rightarrow \text{bool}$ ([ai for all i wh. f(&ai)=true],  [ai for all i wh. f(&ai)=false])$([a_i \text{ for all } i \text{ wh. } f(\&a_i) = \text{true}], \\~~ [a_i \text{ for all } i \text{ wh. } f(\&a_i) = \text{false}])$
Std rev$\text{rev}$ {a0,a1,,an2,an1}$\{a_0, a_1, \ldots, a_{n-2}, a_{n-1}\}$ {an1,an2,,a1,a0}$\{a_{n-1}, a_{n-2}, \ldots, a_1, a_0\}$
Std scan$\text{scan}$ {a0,a1,}$\{a_0, a_1, \ldots\}$, s:&mut S$s : \text{&mut }S$, f:(&mut S,T)Some(U) | None$f : (\text{&mut }S, T) \rightarrow \text{Some}(U) ~|~ \text{None}$ {xi for all i wh. f(s,ai)=Some(xi)}$\{x_i \text{ for all } i \text{ wh. } f(s, a_i) = Some(x_i)\}$
Std skip$\text{skip}$ {a0,,ai1,ai,}$\{a_0, \ldots, a_{i-1}, a_{i}, \ldots\}$, i$i$ {ai,}$\{a_{i}, \ldots\}$
{a0,,an1}$\{a_0, \ldots, a_{n-1}\}$, i wh. in$i \text{ wh. } i \ge n$ {}$\{\}$
Std skip_while$\text{skip_while}$ {a0,,ai,}$\{a_0, \ldots, a_i, \ldots\}$, p:&Tbool$p : \&T \rightarrow \text{bool}$ {ai,} wh. i is first wh. p(&ai)$\{a_i, \ldots\} \text{ wh. } i \text{ is first wh. } p(\&a_i)$
IT slice$\text{slice}$ {a0,,ai,,aj,}$\{a_0, \ldots, a_i, \ldots, a_j, \ldots\}$, ..j$..j$ {a0,,ai,,aj1}$\{a_0, \ldots, a_i, \ldots, a_{j-1}\}$
i..$i..$ {ai,,aj1,}$\{a_i, \ldots, a_{j-1}, \ldots\}$
{a0,,ai,,aj,}$\{a_0, \ldots, a_i, \ldots, \underline{a_j, \ldots}\}$, i..j$i..j$ {ai,,aj1}$\{a_i, \ldots, a_{j-1}\}$
IT step$\text{step}$ {a0,,am,,a2m,}$\{a_0, \ldots, a_m, \ldots, a_{2m}, \ldots\}$, m {a0,am,a2m,}$\{a_0, a_m, a_{2m}, \ldots\}$
Std take$\text{take}$ {a0,,ai1,ai,}$\{a_0, \ldots, a_{i-1}, \underline{a_{i}, \ldots}\}$, i$i$ {a0,,ai1}$\{a_0, \ldots, a_{i-1}\}$
{a0,,an1}$\{a_0, \ldots, a_{n-1}\}$, i wh. in$i \text{ wh. } i \ge n$ {a0,,an1}$\{a_0, \ldots, a_{n-1}\}$
Std take_while$\text{take_while}$ {a0,,ai1,ai,}$\{a_0, \ldots, a_{i-1}, a_i, \underline{\ldots}\}$, p:&Tbool$p : \&T \rightarrow \text{bool}$ {a0,,ai1} wh. i is first wh. p(&ai)=false$\{a_0, \ldots, a_{i-1}\} \text{ wh. } i \text{ is first wh. } p(\&a_i) = \text{false}$
IT take_while_ref$\text{take_while_ref}$ &mut {a0,,ai1,ai,}$\text{&mut }\{a_0, \ldots, a_{i-1}, \underline{a_i, \ldots}\}$, p:&Tbool$p : \&T \rightarrow \text{bool}$ {a0,,ai1} wh. i is first wh. p(&ai)=false$\{a_0, \ldots, a_{i-1}\} \text{ wh. } i \text{ is first wh. } p(\&a_i) = \text{false}$
IT tee$\text{tee}$ {a0,a1,}$\{a_0, a_1, \ldots\}$ ({a0,a1,},{a0,a1,})$(\{a_0, a_1, \ldots\}, \{a_0, a_1, \ldots\})$
Std unzip$\text{unzip}$ {(a0,b0),(a1,b1),}$\{(a_0, b_0), (a_1, b_1), \ldots\}$ ([a0,a1,],[b0,b1,])$([a_0, a_1, \ldots], [b_0, b_1, \ldots])$
IT while_some$\text{while_some}$ {a0,,ai1,ai,}$\{a_0, \ldots, a_{i-1}, a_i, \underline{\ldots}\}$, {xj for all j<i wh. aj=Some(xj)} wh. i is the first wh. ai=None$\begin{array}{ll} \{x_j \text{ for all } j < i \text{ wh. } a_j = Some(x_j)\} \\ \text{ wh. } i \text{ is the first wh. } a_i = \text{None} \\ \end{array}$
Std zip$\text{zip}$ {a0,,ai}$\{a_0, \ldots, a_i\}$, {b0,,bi,bi+1,}$\{b_0, \ldots, b_i, \underline{b_{i+1}, \ldots}\}$ {(a0,b0),,(ai,bi)}$\{(a_0, b_0), \ldots, (a_i, b_i)\}$
{a0,,ai,ai+1,}$\{a_0, \ldots, a_i, a_{i+1}, \underline{\ldots}\}$, {b0,,bi}$\{b_0, \ldots, b_i\}$
IT zip_longest$\text{zip_longest}$ {a0,,ai1,ai,}$\{a_0, \ldots, a_{i-1}, a_i, \ldots\}$ {b0,,bi1}$\{b_0, \ldots, b_{i-1}\}$ {Both(a0,b0),,Both(ai1,bi1),Left(ai),}$\{\text{Both}(a_0, b_0), \ldots, \text{Both}(a_{i-1}, b_{i-1}), \text{Left}(a_i), \ldots\}$
{a0,,ai1}$\{a_0, \ldots, a_{i-1}\}$ {b0,,bi1}$\{b_0, \ldots, b_{i-1}\}$ {Both(a0,b0),,Both(ai1,bi1)}$\{\text{Both}(a_0, b_0), \ldots, \text{Both}(a_{i-1}, b_{i-1})\}$
{a0,,ai1}$\{a_0, \ldots, a_{i-1}\}$ {b0,,bi1,bi,}$\{b_0, \ldots, b_{i-1}, b_i, \ldots\}$ {Both(a0,b0),,Both(ai1,bi1),Right(bi),}$\{\text{Both}(a_0, b_0), \ldots, \text{Both}(a_{i-1}, b_{i-1}), \text{Right}(b_i), \ldots\}$

## Values

Lib Method Input Output
Std all$\text{all}$ &mut {a0,,ai1,ai,}$\text{&mut }\{a_0, \ldots, a_{i-1}, a_i, \underline{\ldots}\}$ p:Tbool$p:T \rightarrow \text{bool}$ p(a0)p(ai1) wh. i is first wh. p(ai)=false$p(a_0) \land \ldots \land p(a_{i-1}) \text{ wh. } i \text{ is first wh. } p(a_i) = \text{false}$
&mut {}$\text{&mut }\{\}$ true$\text{true}$
Std any$\text{any}$ &mut {a0,,ai1,ai,}$\text{&mut }\{a_0, \ldots, a_{i-1}, a_i, \underline{\ldots}\}$ p:Tbool$p:T \rightarrow \text{bool}$ p(a0)p(ai1) wh. i is first wh. p(ai)$p(a_0) \lor \ldots \lor p(a_{i-1}) \text{ wh. } i \text{ is first wh. } p(a_i)$
&mut {}$\text{&mut }\{\}$ false$\text{false}$
Std count$\text{count}$ {n}$\{\underbrace{\ldots}_{n}\}$ n$n$
IT dropn$\text{dropn}$ &mut {a0,,ai1consumed,ai,}$\text{&mut }\{\underbrace{a_0, \ldots, a_{i-1}}_{\text{consumed}}, \underline{a_i, \ldots}\}$ i wh. in$i \text{ wh. } i \le n$ i$i$
&mut {a0,,an1consumed}$\text{&mut }\{\underbrace{a_0, \ldots, a_{n-1}}_{\text{consumed}}\}$ i wh. i>n$i \text{ wh. } i \gt n$ n$n$
Std find$\text{find}$ &mut {a0,,ai,}$\text{&mut }\{a_0, \ldots, a_i, \underline{\ldots}\}$, p:Tbool$p : T \rightarrow \text{bool}$ Some(ai)Nonewh. i is first wh. p(&ai)otherwise$\begin{array}{ll} \text{Some}(a_i) &\text{wh. } i \text{ is first wh. } p(\&a_i) \\ \text{None} & \text{otherwise} \end{array}$
IT find_position$\text{find_position}$ &mut {a0,,ai,}$\text{&mut }\{a_0, \ldots, a_i, \underline{\ldots}\}$, p:Tbool$p : T \rightarrow \text{bool}$ Some((i,ai))Nonewh. i is first wh. p(&ai)otherwise$\begin{array}{ll} \text{Some}((i, a_i)) &\text{wh. } i \text{ is first wh. } p(\&a_i) \\ \text{None} & \text{otherwise} \end{array}$
Std fold$\text{fold}$ {a0,a1,}$\{a_0, a_1, \ldots\}$, init:U$init : U$, :(U,T)U$\circ : (U,T) \rightarrow U$ (((inita0)a1))$(((init \circ a_0) \circ a_1) \circ \ldots)$
{}$\{\}$ init$init$
IT fold1$\text{fold1}$ {a0,a1,a2,}$\{a_0, a_1, a_2, \ldots\}$, :(T,T)T$\circ : (T,T) \rightarrow T$ Some(((a0a1)a2))$\text{Some}(((a_0 \circ a_1) \circ a_2) \circ \ldots)$
{a0}$\{a_0\}$ Some(a0)$\text{Some}(a_0)$
{}$\{\}$ None$\text{None}$
IT fold_results$\text{fold_results}$ &mut {a0,}$\text{&mut }\{a_0, \ldots\}$, init:U$init : U$, :(U,T)U$\circ : (U,T) \rightarrow U$ Ok(fold(x,)) wh. x={xi wh. all ai=Ok(xi)}$\text{Ok}(\text{fold}(x, \circ)) \text{ wh. } x = \{x_i \text{ wh. all } a_i = \text{Ok}(x_i)\}$
&mut {,ai,} wh. ai=Err(..)$\text{&mut }\{\ldots, a_i, \underline{\ldots}\} \text{ wh. } a_i = \text{Err}(..)$, Err(e) wh. i is first wh. ai=Err(e)$\text{Err}(e) \text{ wh. } i \text{ is first wh. } a_i = \text{Err}(e)$
&mut {}$\text{&mut }\{\}$ Ok(init)$\text{Ok}(init)$
Std last$\text{last}$ {,an1}$\{\ldots, a_{n-1}\}$ Some(an1)$\text{Some}(a_{n-1})$
{}$\{\}$ None$\text{None}$
IT join$\text{join}$ {a0,a1,an1}$\{a_0, a_1, \ldots\, a_{n-1}\}$, sep:&str$sep: \text{&str}$ d(a0)sepd(a1)sepd(an1) wh.  d is Display::fmt,  is string concatenation$\begin{array}{ll} d(a_0) \circ sep \circ d(a_1) \circ \ldots \circ sep \circ d(a_{n-1}) \text { wh.}\\~~ d \text{ is Display::fmt, } \circ \text{ is string concatenation} \\ \end{array}$
Std max$\text{max}$ {a0,a1,a2,}$\{a_0, a_1, a_2, \ldots\}$ Some(max(max(max(a0,a1),a2),))$\text{Some}(max(max(max(a_0, a_1), a_2), \ldots))$
{a0}$\{a_0\}$ Some(a0)$\text{Some}(a_0)$
{}$\{\}$ None$\text{None}$
Std min$\text{min}$ {a0,a1,a2,}$\{a_0, a_1, a_2, \ldots\}$ Some(min(min(min(a0,a1),a2),))$\text{Some}(min(min(min(a_0, a_1), a_2), \ldots))$
{a0}$\{a_0\}$ Some(a0)$\text{Some}(a_0)$
{}$\{\}$ None$\text{None}$