pub trait RefFilterable:
RefFunctor
+ Compactable
+ Kind_cdc7cd43dac7585f {
// Provided methods
fn ref_partition_map<'a, A: 'a, E: 'a, O: 'a>(
func: impl Fn(&A) -> Result<O, E> + 'a,
fa: &<Self as Kind_cdc7cd43dac7585f>::Of<'a, A>,
) -> (<Self as Kind_cdc7cd43dac7585f>::Of<'a, E>, <Self as Kind_cdc7cd43dac7585f>::Of<'a, O>) { ... }
fn ref_partition<'a, A: 'a + Clone>(
func: impl Fn(&A) -> bool + 'a,
fa: &<Self as Kind_cdc7cd43dac7585f>::Of<'a, A>,
) -> (<Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>) { ... }
fn ref_filter_map<'a, A: 'a, B: 'a>(
func: impl Fn(&A) -> Option<B> + 'a,
fa: &<Self as Kind_cdc7cd43dac7585f>::Of<'a, A>,
) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, B> { ... }
fn ref_filter<'a, A: 'a + Clone>(
func: impl Fn(&A) -> bool + 'a,
fa: &<Self as Kind_cdc7cd43dac7585f>::Of<'a, A>,
) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, A> { ... }
}Expand description
By-reference filtering of structures.
Similar to Filterable, but closures receive &A instead of A.
This enables filtering collections by reference without consuming elements,
or filtering memoized types that only provide &A access.
Default implementations derive:
ref_partition_mapfromref_map+separate(viaCompactable).ref_partitionfromref_partition_map.ref_filter_mapfromref_map+compact(viaCompactable).ref_filterfromref_filter_map.
Provided Methods§
Sourcefn ref_partition_map<'a, A: 'a, E: 'a, O: 'a>(
func: impl Fn(&A) -> Result<O, E> + 'a,
fa: &<Self as Kind_cdc7cd43dac7585f>::Of<'a, A>,
) -> (<Self as Kind_cdc7cd43dac7585f>::Of<'a, E>, <Self as Kind_cdc7cd43dac7585f>::Of<'a, O>)
fn ref_partition_map<'a, A: 'a, E: 'a, O: 'a>( func: impl Fn(&A) -> Result<O, E> + 'a, fa: &<Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, ) -> (<Self as Kind_cdc7cd43dac7585f>::Of<'a, E>, <Self as Kind_cdc7cd43dac7585f>::Of<'a, O>)
Partitions a structure by reference using a function that returns Result.
§Type Signature
forall A E O. (&A -> Result O E, &Self A) -> (Self E, Self O)
§Type Parameters
'a: The lifetime of the elements.A: The type of the elements in the input structure.E: The type of the error values.O: The type of the success values.
§Parameters
func: The function to apply to each element reference, returning aResult.fa: The structure to partition.
§Returns
A pair of (errors, successes).
§Examples
use fp_library::{
brands::*,
functions::explicit::*,
};
let v = vec![1, 2, 3, 4, 5];
let (small, big) = partition_map::<VecBrand, _, _, _, _, _>(
|x: &i32| if *x > 3 { Ok(*x) } else { Err(*x) },
&v,
);
assert_eq!(big, vec![4, 5]);
assert_eq!(small, vec![1, 2, 3]);Sourcefn ref_partition<'a, A: 'a + Clone>(
func: impl Fn(&A) -> bool + 'a,
fa: &<Self as Kind_cdc7cd43dac7585f>::Of<'a, A>,
) -> (<Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>)
fn ref_partition<'a, A: 'a + Clone>( func: impl Fn(&A) -> bool + 'a, fa: &<Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, ) -> (<Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>)
Partitions a structure by reference using a predicate.
Returns (not_satisfied, satisfied), matching Rust’s Iterator::partition.
§Type Signature
forall A. (&A -> bool, &Self A) -> (Self A, Self A)
§Type Parameters
'a: The lifetime of the elements.A: The type of the elements in the structure.
§Parameters
func: The predicate function.fa: The structure to partition.
§Returns
A pair of (not satisfied, satisfied).
§Examples
use fp_library::{
brands::*,
functions::explicit::*,
};
let v = vec![1, 2, 3, 4, 5];
let (small, big) = partition::<VecBrand, _, _, _>(|x: &i32| *x > 3, &v);
assert_eq!(big, vec![4, 5]);
assert_eq!(small, vec![1, 2, 3]);Sourcefn ref_filter_map<'a, A: 'a, B: 'a>(
func: impl Fn(&A) -> Option<B> + 'a,
fa: &<Self as Kind_cdc7cd43dac7585f>::Of<'a, A>,
) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, B>
fn ref_filter_map<'a, A: 'a, B: 'a>( func: impl Fn(&A) -> Option<B> + 'a, fa: &<Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, ) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, B>
Maps a function over a structure by reference and filters out None results.
§Type Signature
forall A B. (&A -> Option B, &Self A) -> Self B
§Type Parameters
'a: The lifetime of the elements.A: The type of the elements in the input structure.B: The type of the elements in the output structure.
§Parameters
func: The function to apply to each element reference, returning anOption.fa: The structure to filter and map.
§Returns
The structure with None results removed.
§Examples
use fp_library::{
brands::*,
functions::explicit::*,
};
let v = vec![1, 2, 3, 4, 5];
let result =
filter_map::<VecBrand, _, _, _, _>(|x: &i32| if *x > 3 { Some(*x) } else { None }, &v);
assert_eq!(result, vec![4, 5]);Sourcefn ref_filter<'a, A: 'a + Clone>(
func: impl Fn(&A) -> bool + 'a,
fa: &<Self as Kind_cdc7cd43dac7585f>::Of<'a, A>,
) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>
fn ref_filter<'a, A: 'a + Clone>( func: impl Fn(&A) -> bool + 'a, fa: &<Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, ) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>
Filters a structure by reference using a predicate.
§Type Signature
forall A. (&A -> bool, &Self A) -> Self A
§Type Parameters
'a: The lifetime of the elements.A: The type of the elements in the structure.
§Parameters
func: The predicate function.fa: The structure to filter.
§Returns
The structure with elements not satisfying the predicate removed.
§Examples
use fp_library::{
brands::*,
functions::explicit::*,
};
let v = vec![1, 2, 3, 4, 5];
let result = filter::<VecBrand, _, _, _>(|x: &i32| *x > 3, &v);
assert_eq!(result, 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.