Skip to main content

rok_utils/fp/
mod.rs

1//! Functional programming utilities.
2//!
3//! This module provides composition helpers, lazy evaluation, and memoization,
4//! inspired by Laravel's pipeline and AdonisJS middleware patterns.
5//!
6//! # Example
7//!
8//! ```rust
9//! use rok_utils::fp::{pipe, compose, tap};
10//!
11//! // Pipe - thread value through functions
12//! let result = pipe(5, vec![|x| x + 1, |x| x * 2]);
13//! assert_eq!(result, 12); // (5 + 1) * 2
14//!
15//! // Compose - create new functions
16//! let add_then_double = compose(|x: i32| x * 2, |x: i32| x + 1);
17//! assert_eq!(add_then_double(5), 12);
18//!
19//! // Tap - side effects without changing value
20//! let mut log = Vec::new();
21//! let result = tap(42, |v| log.push(*v));
22//! assert_eq!(result, 42);
23//! ```
24
25pub mod compose;
26
27#[cfg(feature = "random")]
28pub use compose::shuffle;
29pub use compose::{apply, compose, memoize, or_default, pipe, retry, tap, Lazy};