external-crates/move/crates/move-stdlib/docs/std/option.md
<a name="std_option"></a>
std::optionThis module defines the Option type and its methods to represent and handle an optional value.
Optionnonesomeis_noneis_somecontainsborrowborrow_with_defaultget_with_defaultfillextractborrow_mutswapswap_or_filldestroy_with_defaultdestroy_somedestroy_noneto_vecdestroydodo_refdo_mutorandand_refmapmap_reffilteris_some_andextract_ordestroy_or<a name="std_option_Option"></a>
OptionAbstraction of a value that may or may not be present. Implemented with a vector of size zero or one because Move bytecode does not have ADTs.
<pre><code><b>public</b> <b>struct</b> <a href="../std/option.md#std_option_Option">Option</a><Element> <b>has</b> <b>copy</b>, drop, store </code></pre> <details> <summary>Fields</summary> <dl> <dt> <code>vec: <a href="../std/vector.md#std_vector">vector</a><Element></code> </dt> <dd> </dd> </dl> </details><a name="@Constants_0"></a>
<a name="std_option_EOPTION_IS_SET"></a>
The <code><a href="../std/option.md#std_option_Option">Option</a></code> is in an invalid state for the operation attempted. The <code><a href="../std/option.md#std_option_Option">Option</a></code> is <code>Some</code> while it should be <code>None</code>.
<pre><code><b>const</b> <a href="../std/option.md#std_option_EOPTION_IS_SET">EOPTION_IS_SET</a>: <a href="../std/u64.md#std_u64">u64</a> = 262144; </code></pre><a name="std_option_EOPTION_NOT_SET"></a>
The <code><a href="../std/option.md#std_option_Option">Option</a></code> is in an invalid state for the operation attempted. The <code><a href="../std/option.md#std_option_Option">Option</a></code> is <code>None</code> while it should be <code>Some</code>.
<pre><code><b>const</b> <a href="../std/option.md#std_option_EOPTION_NOT_SET">EOPTION_NOT_SET</a>: <a href="../std/u64.md#std_u64">u64</a> = 262145; </code></pre><a name="std_option_none"></a>
noneReturn an empty <code><a href="../std/option.md#std_option_Option">Option</a></code>
<pre><code><b>public</b> <b>fun</b> <a href="../std/option.md#std_option_none">none</a><Element>(): <a href="../std/option.md#std_option_Option">std::option::Option</a><Element> </code></pre> <details> <summary>Implementation</summary> <pre><code><b>public</b> <b>fun</b> <a href="../std/option.md#std_option_none">none</a><Element>(): <a href="../std/option.md#std_option_Option">Option</a><Element> { <a href="../std/option.md#std_option_Option">Option</a> { vec: <a href="../std/vector.md#std_vector_empty">vector::empty</a>() } } </code></pre> </details><a name="std_option_some"></a>
someReturn an <code><a href="../std/option.md#std_option_Option">Option</a></code> containing <code>e</code>
<pre><code><b>public</b> <b>fun</b> <a href="../std/option.md#std_option_some">some</a><Element>(e: Element): <a href="../std/option.md#std_option_Option">std::option::Option</a><Element> </code></pre> <details> <summary>Implementation</summary> <pre><code><b>public</b> <b>fun</b> <a href="../std/option.md#std_option_some">some</a><Element>(e: Element): <a href="../std/option.md#std_option_Option">Option</a><Element> { <a href="../std/option.md#std_option_Option">Option</a> { vec: <a href="../std/vector.md#std_vector_singleton">vector::singleton</a>(e) } } </code></pre> </details><a name="std_option_is_none"></a>
is_noneReturn true if <code>t</code> does not hold a value
<pre><code><b>public</b> <b>fun</b> <a href="../std/option.md#std_option_is_none">is_none</a><Element>(t: &<a href="../std/option.md#std_option_Option">std::option::Option</a><Element>): <a href="../std/bool.md#std_bool">bool</a> </code></pre> <details> <summary>Implementation</summary> <pre><code><b>public</b> <b>fun</b> <a href="../std/option.md#std_option_is_none">is_none</a><Element>(t: &<a href="../std/option.md#std_option_Option">Option</a><Element>): <a href="../std/bool.md#std_bool">bool</a> { t.vec.is_empty() } </code></pre> </details><a name="std_option_is_some"></a>
is_someReturn true if <code>t</code> holds a value
<pre><code><b>public</b> <b>fun</b> <a href="../std/option.md#std_option_is_some">is_some</a><Element>(t: &<a href="../std/option.md#std_option_Option">std::option::Option</a><Element>): <a href="../std/bool.md#std_bool">bool</a> </code></pre> <details> <summary>Implementation</summary> <pre><code><b>public</b> <b>fun</b> <a href="../std/option.md#std_option_is_some">is_some</a><Element>(t: &<a href="../std/option.md#std_option_Option">Option</a><Element>): <a href="../std/bool.md#std_bool">bool</a> { !t.vec.is_empty() } </code></pre> </details><a name="std_option_contains"></a>
containsReturn true if the value in <code>t</code> is equal to <code>e_ref</code> Always returns <code><b>false</b></code> if <code>t</code> does not hold a value
<pre><code><b>public</b> <b>fun</b> <a href="../std/option.md#std_option_contains">contains</a><Element>(t: &<a href="../std/option.md#std_option_Option">std::option::Option</a><Element>, e_ref: &Element): <a href="../std/bool.md#std_bool">bool</a> </code></pre> <details> <summary>Implementation</summary> <pre><code><b>public</b> <b>fun</b> <a href="../std/option.md#std_option_contains">contains</a><Element>(t: &<a href="../std/option.md#std_option_Option">Option</a><Element>, e_ref: &Element): <a href="../std/bool.md#std_bool">bool</a> { t.vec.<a href="../std/option.md#std_option_contains">contains</a>(e_ref) } </code></pre> </details><a name="std_option_borrow"></a>
borrowReturn an immutable reference to the value inside <code>t</code> Aborts if <code>t</code> does not hold a value
<pre><code><b>public</b> <b>fun</b> <a href="../std/option.md#std_option_borrow">borrow</a><Element>(t: &<a href="../std/option.md#std_option_Option">std::option::Option</a><Element>): &Element </code></pre> <details> <summary>Implementation</summary> <pre><code><b>public</b> <b>fun</b> <a href="../std/option.md#std_option_borrow">borrow</a><Element>(t: &<a href="../std/option.md#std_option_Option">Option</a><Element>): &Element { <b>assert</b>!(t.<a href="../std/option.md#std_option_is_some">is_some</a>(), <a href="../std/option.md#std_option_EOPTION_NOT_SET">EOPTION_NOT_SET</a>); &t.vec[0] } </code></pre> </details><a name="std_option_borrow_with_default"></a>
borrow_with_defaultReturn a reference to the value inside <code>t</code> if it holds one Return <code>default_ref</code> if <code>t</code> does not hold a value
<pre><code><b>public</b> <b>fun</b> <a href="../std/option.md#std_option_borrow_with_default">borrow_with_default</a><Element>(t: &<a href="../std/option.md#std_option_Option">std::option::Option</a><Element>, default_ref: &Element): &Element </code></pre> <details> <summary>Implementation</summary> <pre><code><b>public</b> <b>fun</b> <a href="../std/option.md#std_option_borrow_with_default">borrow_with_default</a><Element>(t: &<a href="../std/option.md#std_option_Option">Option</a><Element>, default_ref: &Element): &Element { <b>let</b> vec_ref = &t.vec; <b>if</b> (vec_ref.is_empty()) default_ref <b>else</b> &vec_ref[0] } </code></pre> </details><a name="std_option_get_with_default"></a>
get_with_defaultReturn the value inside <code>t</code> if it holds one Return <code>default</code> if <code>t</code> does not hold a value
<pre><code><b>public</b> <b>fun</b> <a href="../std/option.md#std_option_get_with_default">get_with_default</a><Element: <b>copy</b>, drop>(t: &<a href="../std/option.md#std_option_Option">std::option::Option</a><Element>, default: Element): Element </code></pre> <details> <summary>Implementation</summary> <pre><code><b>public</b> <b>fun</b> <a href="../std/option.md#std_option_get_with_default">get_with_default</a><Element: <b>copy</b> + drop>(t: &<a href="../std/option.md#std_option_Option">Option</a><Element>, default: Element): Element { <b>let</b> vec_ref = &t.vec; <b>if</b> (vec_ref.is_empty()) default <b>else</b> vec_ref[0] } </code></pre> </details><a name="std_option_fill"></a>
fillConvert the none option <code>t</code> to a some option by adding <code>e</code>. Aborts if <code>t</code> already holds a value
<pre><code><b>public</b> <b>fun</b> <a href="../std/option.md#std_option_fill">fill</a><Element>(t: &<b>mut</b> <a href="../std/option.md#std_option_Option">std::option::Option</a><Element>, e: Element) </code></pre> <details> <summary>Implementation</summary> <pre><code><b>public</b> <b>fun</b> <a href="../std/option.md#std_option_fill">fill</a><Element>(t: &<b>mut</b> <a href="../std/option.md#std_option_Option">Option</a><Element>, e: Element) { <b>let</b> vec_ref = &<b>mut</b> t.vec; <b>if</b> (vec_ref.is_empty()) vec_ref.push_back(e) <b>else</b> <b>abort</b> <a href="../std/option.md#std_option_EOPTION_IS_SET">EOPTION_IS_SET</a> } </code></pre> </details><a name="std_option_extract"></a>
extractConvert a <code><a href="../std/option.md#std_option_some">some</a></code> option to a <code><a href="../std/option.md#std_option_none">none</a></code> by removing and returning the value stored inside <code>t</code> Aborts if <code>t</code> does not hold a value
<pre><code><b>public</b> <b>fun</b> <a href="../std/option.md#std_option_extract">extract</a><Element>(t: &<b>mut</b> <a href="../std/option.md#std_option_Option">std::option::Option</a><Element>): Element </code></pre> <details> <summary>Implementation</summary> <pre><code><b>public</b> <b>fun</b> <a href="../std/option.md#std_option_extract">extract</a><Element>(t: &<b>mut</b> <a href="../std/option.md#std_option_Option">Option</a><Element>): Element { <b>assert</b>!(t.<a href="../std/option.md#std_option_is_some">is_some</a>(), <a href="../std/option.md#std_option_EOPTION_NOT_SET">EOPTION_NOT_SET</a>); t.vec.pop_back() } </code></pre> </details><a name="std_option_borrow_mut"></a>
borrow_mutReturn a mutable reference to the value inside <code>t</code> Aborts if <code>t</code> does not hold a value
<pre><code><b>public</b> <b>fun</b> <a href="../std/option.md#std_option_borrow_mut">borrow_mut</a><Element>(t: &<b>mut</b> <a href="../std/option.md#std_option_Option">std::option::Option</a><Element>): &<b>mut</b> Element </code></pre> <details> <summary>Implementation</summary> <pre><code><b>public</b> <b>fun</b> <a href="../std/option.md#std_option_borrow_mut">borrow_mut</a><Element>(t: &<b>mut</b> <a href="../std/option.md#std_option_Option">Option</a><Element>): &<b>mut</b> Element { <b>assert</b>!(t.<a href="../std/option.md#std_option_is_some">is_some</a>(), <a href="../std/option.md#std_option_EOPTION_NOT_SET">EOPTION_NOT_SET</a>); &<b>mut</b> t.vec[0] } </code></pre> </details><a name="std_option_swap"></a>
swapSwap the old value inside <code>t</code> with <code>e</code> and return the old value Aborts if <code>t</code> does not hold a value
<pre><code><b>public</b> <b>fun</b> <a href="../std/option.md#std_option_swap">swap</a><Element>(t: &<b>mut</b> <a href="../std/option.md#std_option_Option">std::option::Option</a><Element>, e: Element): Element </code></pre> <details> <summary>Implementation</summary> <pre><code><b>public</b> <b>fun</b> <a href="../std/option.md#std_option_swap">swap</a><Element>(t: &<b>mut</b> <a href="../std/option.md#std_option_Option">Option</a><Element>, e: Element): Element { <b>assert</b>!(t.<a href="../std/option.md#std_option_is_some">is_some</a>(), <a href="../std/option.md#std_option_EOPTION_NOT_SET">EOPTION_NOT_SET</a>); <b>let</b> vec_ref = &<b>mut</b> t.vec; <b>let</b> old_value = vec_ref.pop_back(); vec_ref.push_back(e); old_value } </code></pre> </details><a name="std_option_swap_or_fill"></a>
swap_or_fillSwap the old value inside <code>t</code> with <code>e</code> and return the old value; or if there is no old value, fill it with <code>e</code>. Different from swap(), swap_or_fill() allows for <code>t</code> not holding a value.
<pre><code><b>public</b> <b>fun</b> <a href="../std/option.md#std_option_swap_or_fill">swap_or_fill</a><Element>(t: &<b>mut</b> <a href="../std/option.md#std_option_Option">std::option::Option</a><Element>, e: Element): <a href="../std/option.md#std_option_Option">std::option::Option</a><Element> </code></pre> <details> <summary>Implementation</summary> <pre><code><b>public</b> <b>fun</b> <a href="../std/option.md#std_option_swap_or_fill">swap_or_fill</a><Element>(t: &<b>mut</b> <a href="../std/option.md#std_option_Option">Option</a><Element>, e: Element): <a href="../std/option.md#std_option_Option">Option</a><Element> { <b>let</b> vec_ref = &<b>mut</b> t.vec; <b>let</b> old_value = <b>if</b> (vec_ref.is_empty()) <a href="../std/option.md#std_option_none">none</a>() <b>else</b> <a href="../std/option.md#std_option_some">some</a>(vec_ref.pop_back()); vec_ref.push_back(e); old_value } </code></pre> </details><a name="std_option_destroy_with_default"></a>
destroy_with_defaultDestroys <code>t.</code> If <code>t</code> holds a value, return it. Returns <code>default</code> otherwise
<pre><code><b>public</b> <b>fun</b> <a href="../std/option.md#std_option_destroy_with_default">destroy_with_default</a><Element: drop>(t: <a href="../std/option.md#std_option_Option">std::option::Option</a><Element>, default: Element): Element </code></pre> <details> <summary>Implementation</summary> <pre><code><b>public</b> <b>fun</b> <a href="../std/option.md#std_option_destroy_with_default">destroy_with_default</a><Element: drop>(t: <a href="../std/option.md#std_option_Option">Option</a><Element>, default: Element): Element { <b>let</b> <a href="../std/option.md#std_option_Option">Option</a> { <b>mut</b> vec } = t; <b>if</b> (vec.is_empty()) default <b>else</b> vec.pop_back() } </code></pre> </details><a name="std_option_destroy_some"></a>
destroy_someUnpack <code>t</code> and return its contents Aborts if <code>t</code> does not hold a value
<pre><code><b>public</b> <b>fun</b> <a href="../std/option.md#std_option_destroy_some">destroy_some</a><Element>(t: <a href="../std/option.md#std_option_Option">std::option::Option</a><Element>): Element </code></pre> <details> <summary>Implementation</summary> <pre><code><b>public</b> <b>fun</b> <a href="../std/option.md#std_option_destroy_some">destroy_some</a><Element>(t: <a href="../std/option.md#std_option_Option">Option</a><Element>): Element { <b>assert</b>!(t.<a href="../std/option.md#std_option_is_some">is_some</a>(), <a href="../std/option.md#std_option_EOPTION_NOT_SET">EOPTION_NOT_SET</a>); <b>let</b> <a href="../std/option.md#std_option_Option">Option</a> { <b>mut</b> vec } = t; <b>let</b> elem = vec.pop_back(); vec.destroy_empty(); elem } </code></pre> </details><a name="std_option_destroy_none"></a>
destroy_noneUnpack <code>t</code> Aborts if <code>t</code> holds a value
<pre><code><b>public</b> <b>fun</b> <a href="../std/option.md#std_option_destroy_none">destroy_none</a><Element>(t: <a href="../std/option.md#std_option_Option">std::option::Option</a><Element>) </code></pre> <details> <summary>Implementation</summary> <pre><code><b>public</b> <b>fun</b> <a href="../std/option.md#std_option_destroy_none">destroy_none</a><Element>(t: <a href="../std/option.md#std_option_Option">Option</a><Element>) { <b>assert</b>!(t.<a href="../std/option.md#std_option_is_none">is_none</a>(), <a href="../std/option.md#std_option_EOPTION_IS_SET">EOPTION_IS_SET</a>); <b>let</b> <a href="../std/option.md#std_option_Option">Option</a> { vec } = t; vec.destroy_empty() } </code></pre> </details><a name="std_option_to_vec"></a>
to_vecConvert <code>t</code> into a vector of length 1 if it is <code>Some</code>, and an empty vector otherwise
<pre><code><b>public</b> <b>fun</b> <a href="../std/option.md#std_option_to_vec">to_vec</a><Element>(t: <a href="../std/option.md#std_option_Option">std::option::Option</a><Element>): <a href="../std/vector.md#std_vector">vector</a><Element> </code></pre> <details> <summary>Implementation</summary> <pre><code><b>public</b> <b>fun</b> <a href="../std/option.md#std_option_to_vec">to_vec</a><Element>(t: <a href="../std/option.md#std_option_Option">Option</a><Element>): <a href="../std/vector.md#std_vector">vector</a><Element> { <b>let</b> <a href="../std/option.md#std_option_Option">Option</a> { vec } = t; vec } </code></pre> </details><a name="std_option_destroy"></a>
destroyDestroy <code><a href="../std/option.md#std_option_Option">Option</a><T></code> and call the closure <code>f</code> on the value inside if it holds one.
<pre><code><b>public</b> <b>macro</b> <b>fun</b> <a href="../std/option.md#std_option_destroy">destroy</a><$T, $R: drop>($o: <a href="../std/option.md#std_option_Option">std::option::Option</a><$T>, $f: |$T| -> $R) </code></pre> <details> <summary>Implementation</summary> <pre><code><b>public</b> <b>macro</b> <b>fun</b> <a href="../std/option.md#std_option_destroy">destroy</a><$T, $R: drop>($o: <a href="../std/option.md#std_option_Option">Option</a><$T>, $f: |$T| -> $R) { <b>let</b> o = $o; o.<a href="../std/option.md#std_option_do">do</a>!($f); } </code></pre> </details><a name="std_option_do"></a>
doDestroy <code><a href="../std/option.md#std_option_Option">Option</a><T></code> and call the closure <code>f</code> on the value inside if it holds one.
<pre><code><b>public</b> <b>macro</b> <b>fun</b> <a href="../std/option.md#std_option_do">do</a><$T, $R: drop>($o: <a href="../std/option.md#std_option_Option">std::option::Option</a><$T>, $f: |$T| -> $R) </code></pre> <details> <summary>Implementation</summary> <pre><code><b>public</b> <b>macro</b> <b>fun</b> <a href="../std/option.md#std_option_do">do</a><$T, $R: drop>($o: <a href="../std/option.md#std_option_Option">Option</a><$T>, $f: |$T| -> $R) { <b>let</b> o = $o; <b>if</b> (o.<a href="../std/option.md#std_option_is_some">is_some</a>()) { $f(o.<a href="../std/option.md#std_option_destroy_some">destroy_some</a>()); } <b>else</b> o.<a href="../std/option.md#std_option_destroy_none">destroy_none</a>() } </code></pre> </details><a name="std_option_do_ref"></a>
do_refExecute a closure on the value inside <code>t</code> if it holds one.
<pre><code><b>public</b> <b>macro</b> <b>fun</b> <a href="../std/option.md#std_option_do_ref">do_ref</a><$T, $R: drop>($o: &<a href="../std/option.md#std_option_Option">std::option::Option</a><$T>, $f: |&$T| -> $R) </code></pre> <details> <summary>Implementation</summary> <pre><code><b>public</b> <b>macro</b> <b>fun</b> <a href="../std/option.md#std_option_do_ref">do_ref</a><$T, $R: drop>($o: &<a href="../std/option.md#std_option_Option">Option</a><$T>, $f: |&$T| -> $R) { <b>let</b> o = $o; <b>if</b> (o.<a href="../std/option.md#std_option_is_some">is_some</a>()) { $f(o.<a href="../std/option.md#std_option_borrow">borrow</a>()); } } </code></pre> </details><a name="std_option_do_mut"></a>
do_mutExecute a closure on the mutable reference to the value inside <code>t</code> if it holds one.
<pre><code><b>public</b> <b>macro</b> <b>fun</b> <a href="../std/option.md#std_option_do_mut">do_mut</a><$T, $R: drop>($o: &<b>mut</b> <a href="../std/option.md#std_option_Option">std::option::Option</a><$T>, $f: |&<b>mut</b> $T| -> $R) </code></pre> <details> <summary>Implementation</summary> <pre><code><b>public</b> <b>macro</b> <b>fun</b> <a href="../std/option.md#std_option_do_mut">do_mut</a><$T, $R: drop>($o: &<b>mut</b> <a href="../std/option.md#std_option_Option">Option</a><$T>, $f: |&<b>mut</b> $T| -> $R) { <b>let</b> o = $o; <b>if</b> (o.<a href="../std/option.md#std_option_is_some">is_some</a>()) { $f(o.<a href="../std/option.md#std_option_borrow_mut">borrow_mut</a>()); } } </code></pre> </details><a name="std_option_or"></a>
orSelect the first <code>Some</code> value from the two options, or <code>None</code> if both are <code>None</code>. Equivalent to Rust's <code>a.<a href="../std/option.md#std_option_or">or</a>(b)</code>.
<pre><code><b>public</b> <b>macro</b> <b>fun</b> <a href="../std/option.md#std_option_or">or</a><$T>($o: <a href="../std/option.md#std_option_Option">std::option::Option</a><$T>, $default: <a href="../std/option.md#std_option_Option">std::option::Option</a><$T>): <a href="../std/option.md#std_option_Option">std::option::Option</a><$T> </code></pre> <details> <summary>Implementation</summary> <pre><code><b>public</b> <b>macro</b> <b>fun</b> <a href="../std/option.md#std_option_or">or</a><$T>($o: <a href="../std/option.md#std_option_Option">Option</a><$T>, $default: <a href="../std/option.md#std_option_Option">Option</a><$T>): <a href="../std/option.md#std_option_Option">Option</a><$T> { <b>let</b> o = $o; <b>if</b> (o.<a href="../std/option.md#std_option_is_some">is_some</a>()) { o } <b>else</b> { o.<a href="../std/option.md#std_option_destroy_none">destroy_none</a>(); $default } } </code></pre> </details><a name="std_option_and"></a>
andIf the value is <code>Some</code>, call the closure <code>f</code> on it. Otherwise, return <code>None</code>. Equivalent to Rust's <code>t.and_then(f)</code>.
<pre><code><b>public</b> <b>macro</b> <b>fun</b> <a href="../std/option.md#std_option_and">and</a><$T, $U>($o: <a href="../std/option.md#std_option_Option">std::option::Option</a><$T>, $f: |$T| -> <a href="../std/option.md#std_option_Option">std::option::Option</a><$U>): <a href="../std/option.md#std_option_Option">std::option::Option</a><$U> </code></pre> <details> <summary>Implementation</summary> <pre><code><b>public</b> <b>macro</b> <b>fun</b> <a href="../std/option.md#std_option_and">and</a><$T, $U>($o: <a href="../std/option.md#std_option_Option">Option</a><$T>, $f: |$T| -> <a href="../std/option.md#std_option_Option">Option</a><$U>): <a href="../std/option.md#std_option_Option">Option</a><$U> { <b>let</b> o = $o; <b>if</b> (o.<a href="../std/option.md#std_option_is_some">is_some</a>()) { $f(o.<a href="../std/option.md#std_option_destroy_some">destroy_some</a>()) } <b>else</b> { o.<a href="../std/option.md#std_option_destroy_none">destroy_none</a>(); <a href="../std/option.md#std_option_none">none</a>() } } </code></pre> </details><a name="std_option_and_ref"></a>
and_refIf the value is <code>Some</code>, call the closure <code>f</code> on it. Otherwise, return <code>None</code>. Equivalent to Rust's <code>t.and_then(f)</code>.
<pre><code><b>public</b> <b>macro</b> <b>fun</b> <a href="../std/option.md#std_option_and_ref">and_ref</a><$T, $U>($o: &<a href="../std/option.md#std_option_Option">std::option::Option</a><$T>, $f: |&$T| -> <a href="../std/option.md#std_option_Option">std::option::Option</a><$U>): <a href="../std/option.md#std_option_Option">std::option::Option</a><$U> </code></pre> <details> <summary>Implementation</summary> <pre><code><b>public</b> <b>macro</b> <b>fun</b> <a href="../std/option.md#std_option_and_ref">and_ref</a><$T, $U>($o: &<a href="../std/option.md#std_option_Option">Option</a><$T>, $f: |&$T| -> <a href="../std/option.md#std_option_Option">Option</a><$U>): <a href="../std/option.md#std_option_Option">Option</a><$U> { <b>let</b> o = $o; <b>if</b> (o.<a href="../std/option.md#std_option_is_some">is_some</a>()) $f(o.<a href="../std/option.md#std_option_borrow">borrow</a>()) <b>else</b> <a href="../std/option.md#std_option_none">none</a>() } </code></pre> </details><a name="std_option_map"></a>
mapMap an <code><a href="../std/option.md#std_option_Option">Option</a><T></code> to <code><a href="../std/option.md#std_option_Option">Option</a><U></code> by applying a function to a contained value. Equivalent to Rust's <code>t.<a href="../std/option.md#std_option_map">map</a>(f)</code>.
<pre><code><b>public</b> <b>macro</b> <b>fun</b> <a href="../std/option.md#std_option_map">map</a><$T, $U>($o: <a href="../std/option.md#std_option_Option">std::option::Option</a><$T>, $f: |$T| -> $U): <a href="../std/option.md#std_option_Option">std::option::Option</a><$U> </code></pre> <details> <summary>Implementation</summary> <pre><code><b>public</b> <b>macro</b> <b>fun</b> <a href="../std/option.md#std_option_map">map</a><$T, $U>($o: <a href="../std/option.md#std_option_Option">Option</a><$T>, $f: |$T| -> $U): <a href="../std/option.md#std_option_Option">Option</a><$U> { <b>let</b> o = $o; <b>if</b> (o.<a href="../std/option.md#std_option_is_some">is_some</a>()) { <a href="../std/option.md#std_option_some">some</a>($f(o.<a href="../std/option.md#std_option_destroy_some">destroy_some</a>())) } <b>else</b> { o.<a href="../std/option.md#std_option_destroy_none">destroy_none</a>(); <a href="../std/option.md#std_option_none">none</a>() } } </code></pre> </details><a name="std_option_map_ref"></a>
map_refMap an <code><a href="../std/option.md#std_option_Option">Option</a><T></code> value to <code><a href="../std/option.md#std_option_Option">Option</a><U></code> by applying a function to a contained value by reference. Original <code><a href="../std/option.md#std_option_Option">Option</a><T></code> is preserved. Equivalent to Rust's <code>t.<a href="../std/option.md#std_option_map">map</a>(f)</code>.
<pre><code><b>public</b> <b>macro</b> <b>fun</b> <a href="../std/option.md#std_option_map_ref">map_ref</a><$T, $U>($o: &<a href="../std/option.md#std_option_Option">std::option::Option</a><$T>, $f: |&$T| -> $U): <a href="../std/option.md#std_option_Option">std::option::Option</a><$U> </code></pre> <details> <summary>Implementation</summary> <pre><code><b>public</b> <b>macro</b> <b>fun</b> <a href="../std/option.md#std_option_map_ref">map_ref</a><$T, $U>($o: &<a href="../std/option.md#std_option_Option">Option</a><$T>, $f: |&$T| -> $U): <a href="../std/option.md#std_option_Option">Option</a><$U> { <b>let</b> o = $o; <b>if</b> (o.<a href="../std/option.md#std_option_is_some">is_some</a>()) <a href="../std/option.md#std_option_some">some</a>($f(o.<a href="../std/option.md#std_option_borrow">borrow</a>())) <b>else</b> <a href="../std/option.md#std_option_none">none</a>() } </code></pre> </details><a name="std_option_filter"></a>
filterReturn <code>None</code> if the value is <code>None</code>, otherwise return <code><a href="../std/option.md#std_option_Option">Option</a><T></code> if the predicate <code>f</code> returns true.
<pre><code><b>public</b> <b>macro</b> <b>fun</b> <a href="../std/option.md#std_option_filter">filter</a><$T: drop>($o: <a href="../std/option.md#std_option_Option">std::option::Option</a><$T>, $f: |&$T| -> <a href="../std/bool.md#std_bool">bool</a>): <a href="../std/option.md#std_option_Option">std::option::Option</a><$T> </code></pre> <details> <summary>Implementation</summary> <pre><code><b>public</b> <b>macro</b> <b>fun</b> <a href="../std/option.md#std_option_filter">filter</a><$T: drop>($o: <a href="../std/option.md#std_option_Option">Option</a><$T>, $f: |&$T| -> <a href="../std/bool.md#std_bool">bool</a>): <a href="../std/option.md#std_option_Option">Option</a><$T> { <b>let</b> o = $o; <b>if</b> (o.<a href="../std/option.md#std_option_is_some">is_some</a>() && $f(o.<a href="../std/option.md#std_option_borrow">borrow</a>())) o <b>else</b> <a href="../std/option.md#std_option_none">none</a>() } </code></pre> </details><a name="std_option_is_some_and"></a>
is_some_andReturn <code><b>false</b></code> if the value is <code>None</code>, otherwise return the result of the predicate <code>f</code>.
<pre><code><b>public</b> <b>macro</b> <b>fun</b> <a href="../std/option.md#std_option_is_some_and">is_some_and</a><$T>($o: &<a href="../std/option.md#std_option_Option">std::option::Option</a><$T>, $f: |&$T| -> <a href="../std/bool.md#std_bool">bool</a>): <a href="../std/bool.md#std_bool">bool</a> </code></pre> <details> <summary>Implementation</summary> <pre><code><b>public</b> <b>macro</b> <b>fun</b> <a href="../std/option.md#std_option_is_some_and">is_some_and</a><$T>($o: &<a href="../std/option.md#std_option_Option">Option</a><$T>, $f: |&$T| -> <a href="../std/bool.md#std_bool">bool</a>): <a href="../std/bool.md#std_bool">bool</a> { <b>let</b> o = $o; o.<a href="../std/option.md#std_option_is_some">is_some</a>() && $f(o.<a href="../std/option.md#std_option_borrow">borrow</a>()) } </code></pre> </details><a name="std_option_extract_or"></a>
extract_orExtract the value inside <code><a href="../std/option.md#std_option_Option">Option</a><T></code> if it holds one, or <code>default</code> otherwise. Similar to <code><a href="../std/option.md#std_option_destroy_or">destroy_or</a></code>, but modifying the input <code><a href="../std/option.md#std_option_Option">Option</a></code> via a mutable reference.
<pre><code><b>public</b> <b>macro</b> <b>fun</b> <a href="../std/option.md#std_option_extract_or">extract_or</a><$T>($o: &<b>mut</b> <a href="../std/option.md#std_option_Option">std::option::Option</a><$T>, $default: $T): $T </code></pre> <details> <summary>Implementation</summary> <pre><code><b>public</b> <b>macro</b> <b>fun</b> <a href="../std/option.md#std_option_extract_or">extract_or</a><$T>($o: &<b>mut</b> <a href="../std/option.md#std_option_Option">Option</a><$T>, $default: $T): $T { <b>let</b> o = $o; <b>if</b> (o.<a href="../std/option.md#std_option_is_some">is_some</a>()) o.<a href="../std/option.md#std_option_extract">extract</a>() <b>else</b> $default } </code></pre> </details><a name="std_option_destroy_or"></a>
destroy_orDestroy <code><a href="../std/option.md#std_option_Option">Option</a><T></code> and return the value inside if it holds one, or <code>default</code> otherwise. Equivalent to Rust's <code>t.unwrap_or(default)</code>.
Note: this function is a more efficient version of <code><a href="../std/option.md#std_option_destroy_with_default">destroy_with_default</a></code>, as it does not evaluate the default value unless necessary. The <code><a href="../std/option.md#std_option_destroy_with_default">destroy_with_default</a></code> function should be deprecated in favor of this function.
<pre><code><b>public</b> <b>macro</b> <b>fun</b> <a href="../std/option.md#std_option_destroy_or">destroy_or</a><$T>($o: <a href="../std/option.md#std_option_Option">std::option::Option</a><$T>, $default: $T): $T </code></pre> <details> <summary>Implementation</summary> <pre><code><b>public</b> <b>macro</b> <b>fun</b> <a href="../std/option.md#std_option_destroy_or">destroy_or</a><$T>($o: <a href="../std/option.md#std_option_Option">Option</a><$T>, $default: $T): $T { <b>let</b> o = $o; <b>if</b> (o.<a href="../std/option.md#std_option_is_some">is_some</a>()) { o.<a href="../std/option.md#std_option_destroy_some">destroy_some</a>() } <b>else</b> { o.<a href="../std/option.md#std_option_destroy_none">destroy_none</a>(); $default } } </code></pre> </details>