pub fn apply<'a, FnBrand, Brand, A, B, WrappedFn, FF, FA>(
ff: FF,
fa: FA,
) -> <Brand as Kind_cdc7cd43dac7585f>::Of<'a, B>where
Brand: Kind_cdc7cd43dac7585f,
A: 'a,
B: 'a,
WrappedFn: 'a + InferableFnBrand<FnBrand, A, B, <FA as InferableBrand_cdc7cd43dac7585f<'a, Brand, A>>::Marker>,
FA: InferableBrand_cdc7cd43dac7585f<'a, Brand, A>,
<FA as InferableBrand_cdc7cd43dac7585f<'a, Brand, A>>::Marker: ClosureMode,
FnBrand: CloneFn<<FA as InferableBrand_cdc7cd43dac7585f<'a, Brand, A>>::Marker> + 'a,
FF: InferableBrand_cdc7cd43dac7585f<'a, Brand, WrappedFn> + ApplyDispatch<'a, FnBrand, Brand, A, B, WrappedFn, FA, <FA as InferableBrand_cdc7cd43dac7585f<'a, Brand, A>>::Marker>,Expand description
Applies a container of functions to a container of values, inferring Brand, FnBrand, and Val/Ref dispatch from the container types.
- Brand is resolved via dual InferableBrand bounds on FF and FA.
- FnBrand is resolved via
InferableFnBrandfrom the wrapper type WrappedFn. - Val/Ref dispatch is resolved via the Marker projected from FA’s InferableBrand.
- The
CloneFnmode is tied to the Marker viaCloneFn<Marker>.
No turbofish arguments are needed for single-brand types.
For types where inference fails (e.g., multi-brand types like Result),
use explicit::apply with a turbofish.
§Type Signature
forall Brand A B. Semiapplicative Brand => (Brand (A -> B), Brand A) -> Brand B
§Type Parameters
'a: The lifetime of the values.FnBrand: The function-wrapping brand, inferred via InferableFnBrand.Brand: The brand, inferred via InferableBrand from FF and FA.A: The type of the value(s) inside the value container.B: The result type after applying the function.WrappedFn: The concrete wrapped-function type, inferred from FF’s element type.FF: The function container type.FA: The value container type.
§Parameters
ff: The container of function(s) to apply.fa: The container of value(s) to apply the function(s) to.
§Returns
A new container with the function(s) applied to the value(s).
§Examples
use fp_library::{
brands::*,
classes::*,
functions::*,
};
// Val: owned containers
let f = Some(lift_fn_new::<RcFnBrand, _, _>(|x: i32| x * 2));
let y: Option<i32> = apply(f, Some(5));
assert_eq!(y, Some(10));
// Ref: borrowed containers
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));