Skip to main content

TapWith

Trait TapWith 

Source
pub trait TapWith<const ARITY: usize, AState, PState, RState> {
    // Provided method
    fn tap_with<'a, R, F, P, Args>(self, proj: P, f: F) -> F::Curry<'a>
       where F: ImplCurryWith<ARITY, Args, AState, PState, RState, Self, P, R>,
             Self: Sized { ... }
}
Expand description

Extension trait for running side effects on a projection of the value.

Provided Methods§

Source

fn tap_with<'a, R, F, P, Args>(self, proj: P, f: F) -> F::Curry<'a>
where F: ImplCurryWith<ARITY, Args, AState, PState, RState, Self, P, R>, Self: Sized,

Projects the value into Option, runs a side-effect if Some, and returns the original value.

Useful for control flow, and for focusing on a specific field for validation or modification.

§Example
struct Config { id: i32 }
fn check(id: &i32) { assert!(*id > 0); }

let c = Config { id: 10 };
// Explicit type often required to distinguish between mutable/immutable source paths
c.tap_with(|c: &Config| Some(&c.id), check)();

Implementors§

Source§

impl<const ARITY: usize, AState, PState, RState, T> TapWith<ARITY, AState, PState, RState> for T