[−][src]Trait kai::Bind
Allows the binding and mutation of a value in a single line
This is useful when you want a functional interface wrapping a mutable one, or when you really feel like doing something in one line.
bind_mut
example
use kai::*; // Turn this let mut a = vec![1, 4, 2, 1, 3, 2, 2]; a.sort(); a.dedup(); // Into this let b = vec![1, 4, 2, 1, 3, 2, 2].bind_mut(|v| v.sort()).bind_mut(Vec::dedup); assert_eq!(a, b);
bind_map
example
use kai::*; // Turn this let x = 2i32.pow(3); let a = x / 3; // Into this let b = 2i32.pow(3).bind_map(|x| x / 3); assert_eq!(a, b);
Provided methods
fn bind_mut<F>(self, f: F) -> Self where
F: FnMut(&mut Self),
F: FnMut(&mut Self),
Binds the value, mutates it, and returns it
fn bind_map<F, R>(self, f: F) -> R where
F: FnMut(Self) -> R,
F: FnMut(Self) -> R,
Binds the value, maps it with the function, and returns the mapped value