set

Function set 

Source
pub fn set<Root, Value>(
    keypath: WritableKeyPath<Root, Value>,
    value: Value,
) -> impl Fn(Root) -> Root
where Root: Clone + 'static, Value: Clone + 'static,
Expand description

Produces an immutable setter function for a given key path and constant value. Equivalent to Swift’s set<Root, Value>(_ keyPath: WritableKeyPath<Root, Value>, _ value: Value) -> (Root) -> Root

§Examples

use overture_core::keypath::{WritableKeyPath, set};

let age_keypath = WritableKeyPath::new(
    |person: &Person| person.age,
    |person: &mut Person, age| person.age = age
);
let set_age_25 = set(age_keypath, 25);
let person = Person { name: "Alice".to_string(), age: 30 };
let updated = set_age_25(person);
assert_eq!(updated.age, 25);