compose_throwing

Function compose_throwing 

Source
pub fn compose_throwing<A, B, C, E, F, G>(
    f: F,
    g: G,
) -> impl Fn(A) -> Result<C, E>
where F: Fn(B) -> Result<C, E> + 'static, G: Fn(A) -> Result<B, E> + 'static,
Expand description

Backward composition of two throwing functions with shallow cloning optimization.

Uses Rc to enable shallow cloning of functions, reducing memory overhead when the same function is used multiple times in composed pipelines.

§Arguments

  • f - A function that takes a value in B and returns a Result<C, E>
  • g - A function that takes a value in A and returns a Result<B, E>

§Returns

A new function that takes a value in A and returns a Result<C, E>

§Example

use overture_core::compose_rs::compose_throwing;

let parse_int = |s: &str| s.parse::<i32>().map_err(|_| "Parse error");
let add_one = |x: i32| Ok(x + 1);
let composed = compose_throwing(add_one, parse_int);

assert_eq!(composed("5"), Ok(6));
assert_eq!(composed("invalid"), Err("Parse error"));