Skip to main content

Module semiapplicative

Module semiapplicative 

Source
Expand description

Dispatch for Semiapplicative::apply and RefSemiapplicative::ref_apply.

Provides unified Val/Ref dispatch via the ApplyDispatch trait, the InferableFnBrand trait for FnBrand inference, and an inference wrapper apply that infers both Brand and FnBrand from the container types.

§Examples

use fp_library::{
	brands::*,
	classes::*,
	functions::*,
};

// Val: owned containers, Fn(A) -> B closures
let f = Some(lift_fn_new::<RcFnBrand, _, _>(|x: i32| x * 2));
let x = Some(5);
let y: Option<i32> = apply(f, x);
assert_eq!(y, Some(10));

// Ref: borrowed containers, Fn(&A) -> B closures
let f = Some(std::rc::Rc::new(|x: &i32| *x * 2) as std::rc::Rc<dyn Fn(&i32) -> i32>);
let x = Some(5);
let y: Option<i32> = apply(&f, &x);
assert_eq!(y, Some(10));

Traits§

ApplyDispatch
Trait that routes an apply operation to the appropriate type class method.
InferableFnBrand
Maps a concrete wrapped-function type back to its FnBrand, parameterized by closure mode.

Functions§

apply
Applies a container of functions to a container of values, inferring Brand, FnBrand, and Val/Ref dispatch from the container types.