pub trait Pipe<const ARITY: usize, AState, RState> {
// Provided method
fn pipe<R, F, Args>(self, f: F) -> F::Curry
where F: Curry<ARITY, Args, AState, RState, PipeMark, Self, R>,
Self: Sized { ... }
}Expand description
Extension trait for transforming values.
Provided Methods§
Sourcefn pipe<R, F, Args>(self, f: F) -> F::Currywhere
F: Curry<ARITY, Args, AState, RState, PipeMark, Self, R>,
Self: Sized,
fn pipe<R, F, Args>(self, f: F) -> F::Currywhere
F: Curry<ARITY, Args, AState, RState, PipeMark, Self, R>,
Self: Sized,
Curries self as the first argument of f, returning a closure over
the remaining arguments. The returned closure is a standalone value,
so pipe doubles as partial application.
§Examples
fn add(x: i32, y: i32) -> i32 { x + y }
let result = 2
.pipe(add)(3)
.pipe(|x, a, b| a * x + b)(10, 1)
.pipe(Option::Some)();
assert_eq!(result, Some(51));
struct Threshold(i32);
impl Threshold {
fn check(&self, val: i32) -> bool { val > self.0 }
}
let is_high = Threshold(50).pipe(Threshold::check);
assert_eq!([20, 60, 80].map(is_high), [false, true, true]);
fn first_mut(slice: &mut [i32; 3]) -> &mut i32 { &mut slice[0] }
let mut data = [10, 20, 30];
*(&mut data).pipe(first_mut)() = 99;
assert_eq!(data[0], 99);