Expand description
Composable operations for keypath functions
This module provides composable operations that allow chaining keypath transformations in a functional programming style. It includes pipe operations, conditional operations, and lazy evaluation patterns.
§Examples
§Basic Composition
use rust_prelude_plus::prelude::*;
use key_paths_derive::Keypath;
use std::rc::Rc;
#[derive(Keypath, Debug, Clone)]
struct Person {
name: String,
age: u32,
}
let people = vec![
Rc::new(Person { name: "Alice".to_string(), age: 30 }),
Rc::new(Person { name: "Bob".to_string(), age: 25 }),
];
// Compose operations using pipe
let result = pipe(people, |people| {
people.iter()
.filter_by_keypath(Person::age(), |&age| age < 30)
.map_keypath(Person::name(), |name| name.clone())
.collect::<Vec<_>>()
});§Conditional Operations
use rust_prelude_plus::prelude::*;
use key_paths_derive::Keypath;
use std::rc::Rc;
#[derive(Keypath, Debug, Clone)]
struct Product {
name: String,
price: f64,
category: String,
}
let products = vec![
Rc::new(Product { name: "Laptop".to_string(), price: 999.99, category: "Electronics".to_string() }),
Rc::new(Product { name: "Book".to_string(), price: 19.99, category: "Books".to_string() }),
];
// Apply discount only to electronics
let discounted_products = products
.iter()
.when_keypath(Product::category(), |cat| cat == "Electronics", |iter| {
iter.map_keypath(Product::price(), |&price| price * 0.9)
})
.collect::<Vec<_>>();Modules§
- utils
- Utility functions for common keypath operations
Structs§
- KeyPaths
Chain - KeyPaths chain for composable operations
Traits§
- Composable
Iterator - Extension trait for adding composable operations to iterators
Functions§
- chain_
keypath_ ops - Chain multiple keypath transformations
- pipe
- Function composition for keypath operations
- unless_
keypath - Inverse conditional operations
- when_
keypath - Conditional keypath operations