Skip to main content

pipe

Macro pipe 

Source
macro_rules! pipe {
    ($e:expr) => { ... };
    ($in:expr => $($i:ident).+ $(())? $(=> $($tail:tt)+)?) => { ... };
    ($in:expr => $($i:ident).+ ($($($arg_head:expr_2021),*,)? $(_ $(, $arg_tail:expr_2021)*),*) $(=> $($tail:tt)+)?) => { ... };
    ($in:expr => ($e:expr) ($($($arg_head:expr_2021),*,)? $(_ $(, $arg_tail:expr_2021)*),*) $(=> $($tail:tt)+)?) => { ... };
    ($in:expr => $e:expr $(=> $($tail:tt)+)?) => { ... };
}
Expand description

A macro which evaluates functions from left to right, rather than from inside to outside.

Syntax: pipe!(init => fn1 => fn2 => ...)

Each function is either the name of a single-argument function (optionally with parentheses), an expression which is parenthesizable and callable as a single-argument function (usually a lambda), or a name/parenthesized expression followed by a parenthesized comma-separated list of arguments with one or more arguments left as blank (_). All function calls and expressions to the left will be evaluated, stored in a temporary, and then inserted into the current function call in place of any blanks.