pub fn over<Root, Value>(
keypath: WritableKeyPath<Root, Value>,
update: impl Fn(Value) -> Value + 'static,
) -> impl Fn(Root) -> RootExpand description
Produces an immutable setter function for a given key path and update function. Equivalent to Swift’s over<Root, Value>(_ keyPath: WritableKeyPath<Root, Value>, _ update: @escaping (Value) -> Value) -> (Root) -> Root
§Examples
use overture_core::keypath::{WritableKeyPath, over};
let age_keypath = WritableKeyPath::new(
|person: &Person| person.age,
|person: &mut Person, age| person.age = age
);
let double_age = over(age_keypath, |age| age * 2);
let person = Person { name: "Alice".to_string(), age: 30 };
let updated = double_age(person);
assert_eq!(updated.age, 60);