pub trait RefWitherable:
RefFilterable
+ RefTraversable
+ Kind_cdc7cd43dac7585f {
// Provided methods
fn ref_wilt<'a, FnBrand, M: Applicative, A: 'a + Clone, E: 'a + Clone, O: 'a + Clone>(
func: impl Fn(&A) -> <M as Kind_cdc7cd43dac7585f>::Of<'a, Result<O, E>> + 'a,
ta: &<Self as Kind_cdc7cd43dac7585f>::Of<'a, A>,
) -> <M as Kind_cdc7cd43dac7585f>::Of<'a, (<Self as Kind_cdc7cd43dac7585f>::Of<'a, E>, <Self as Kind_cdc7cd43dac7585f>::Of<'a, O>)>
where FnBrand: LiftFn + 'a,
<Self as Kind_cdc7cd43dac7585f>::Of<'a, Result<O, E>>: Clone,
<M as Kind_cdc7cd43dac7585f>::Of<'a, Result<O, E>>: Clone { ... }
fn ref_wither<'a, FnBrand, M: Applicative, A: 'a + Clone, B: 'a + Clone>(
func: impl Fn(&A) -> <M as Kind_cdc7cd43dac7585f>::Of<'a, Option<B>> + 'a,
ta: &<Self as Kind_cdc7cd43dac7585f>::Of<'a, A>,
) -> <M as Kind_cdc7cd43dac7585f>::Of<'a, <Self as Kind_cdc7cd43dac7585f>::Of<'a, B>>
where FnBrand: LiftFn + 'a,
<Self as Kind_cdc7cd43dac7585f>::Of<'a, Option<B>>: Clone,
<M as Kind_cdc7cd43dac7585f>::Of<'a, Option<B>>: Clone { ... }
}Expand description
By-reference withering (effectful filtering) of structures.
Similar to Witherable, but closures receive &A instead of A.
Combines by-reference traversal with filtering in an applicative context.
Default implementations derive:
ref_wiltfromref_traverse+separate.ref_witherfromref_traverse+compact.
Provided Methods§
Sourcefn ref_wilt<'a, FnBrand, M: Applicative, A: 'a + Clone, E: 'a + Clone, O: 'a + Clone>(
func: impl Fn(&A) -> <M as Kind_cdc7cd43dac7585f>::Of<'a, Result<O, E>> + 'a,
ta: &<Self as Kind_cdc7cd43dac7585f>::Of<'a, A>,
) -> <M as Kind_cdc7cd43dac7585f>::Of<'a, (<Self as Kind_cdc7cd43dac7585f>::Of<'a, E>, <Self as Kind_cdc7cd43dac7585f>::Of<'a, O>)>where
FnBrand: LiftFn + 'a,
<Self as Kind_cdc7cd43dac7585f>::Of<'a, Result<O, E>>: Clone,
<M as Kind_cdc7cd43dac7585f>::Of<'a, Result<O, E>>: Clone,
fn ref_wilt<'a, FnBrand, M: Applicative, A: 'a + Clone, E: 'a + Clone, O: 'a + Clone>(
func: impl Fn(&A) -> <M as Kind_cdc7cd43dac7585f>::Of<'a, Result<O, E>> + 'a,
ta: &<Self as Kind_cdc7cd43dac7585f>::Of<'a, A>,
) -> <M as Kind_cdc7cd43dac7585f>::Of<'a, (<Self as Kind_cdc7cd43dac7585f>::Of<'a, E>, <Self as Kind_cdc7cd43dac7585f>::Of<'a, O>)>where
FnBrand: LiftFn + 'a,
<Self as Kind_cdc7cd43dac7585f>::Of<'a, Result<O, E>>: Clone,
<M as Kind_cdc7cd43dac7585f>::Of<'a, Result<O, E>>: Clone,
Partitions by reference in an applicative context.
Maps each element by reference to a computation producing Result<O, E>,
traverses the structure, then separates the results.
§Type Signature
forall M A E O. Applicative M => (&A -> M (Result O E), &Self A) -> M (Self E, Self O)
§Type Parameters
'a: The lifetime of the elements.FnBrand: The brand of the cloneable function wrapper.M: The applicative context.A: The type of the input elements.E: The error type.O: The success type.
§Parameters
func: The function to apply to each element reference.ta: The structure to partition.
§Returns
The partitioned structure in the applicative context.
§Examples
use fp_library::{
brands::*,
functions::explicit::*,
};
let v = vec![1, 2, 3, 4, 5];
let result: Option<(Vec<i32>, Vec<i32>)> =
wilt::<RcFnBrand, VecBrand, OptionBrand, _, _, _, _, _>(
|x: &i32| Some(if *x > 3 { Ok(*x) } else { Err(*x) }),
&v,
);
assert_eq!(result, Some((vec![1, 2, 3], vec![4, 5])));Sourcefn ref_wither<'a, FnBrand, M: Applicative, A: 'a + Clone, B: 'a + Clone>(
func: impl Fn(&A) -> <M as Kind_cdc7cd43dac7585f>::Of<'a, Option<B>> + 'a,
ta: &<Self as Kind_cdc7cd43dac7585f>::Of<'a, A>,
) -> <M as Kind_cdc7cd43dac7585f>::Of<'a, <Self as Kind_cdc7cd43dac7585f>::Of<'a, B>>where
FnBrand: LiftFn + 'a,
<Self as Kind_cdc7cd43dac7585f>::Of<'a, Option<B>>: Clone,
<M as Kind_cdc7cd43dac7585f>::Of<'a, Option<B>>: Clone,
fn ref_wither<'a, FnBrand, M: Applicative, A: 'a + Clone, B: 'a + Clone>(
func: impl Fn(&A) -> <M as Kind_cdc7cd43dac7585f>::Of<'a, Option<B>> + 'a,
ta: &<Self as Kind_cdc7cd43dac7585f>::Of<'a, A>,
) -> <M as Kind_cdc7cd43dac7585f>::Of<'a, <Self as Kind_cdc7cd43dac7585f>::Of<'a, B>>where
FnBrand: LiftFn + 'a,
<Self as Kind_cdc7cd43dac7585f>::Of<'a, Option<B>>: Clone,
<M as Kind_cdc7cd43dac7585f>::Of<'a, Option<B>>: Clone,
Filters by reference in an applicative context.
Maps each element by reference to a computation producing Option<B>,
traverses the structure, then compacts the results.
§Type Signature
forall M A B. Applicative M => (&A -> M (Option B), &Self A) -> M (Self B)
§Type Parameters
'a: The lifetime of the elements.FnBrand: The brand of the cloneable function wrapper.M: The applicative context.A: The type of the input elements.B: The type of the output elements.
§Parameters
func: The function to apply to each element reference.ta: The structure to filter.
§Returns
The filtered structure in the applicative context.
§Examples
use fp_library::{
brands::*,
functions::explicit::*,
};
let v = vec![1, 2, 3, 4, 5];
let result: Option<Vec<i32>> = wither::<RcFnBrand, VecBrand, OptionBrand, _, _, _, _>(
|x: &i32| if *x > 3 { Some(Some(*x)) } else { Some(None) },
&v,
);
assert_eq!(result, Some(vec![4, 5]));Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.