pub trait Bind: Sized {
// Provided methods
fn bind_mut<F>(self, f: F) -> Self
where F: FnMut(&mut Self) { ... }
fn bind_map<F, R>(self, f: F) -> R
where F: FnMut(Self) -> R { ... }
}Expand description
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§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.