pub trait FoldableA<'r, A: 'r>: HKST<'r, A> {
// Required methods
fn fold<F>(&'r self, z: A, f: F) -> A
where F: FnMut(A, &A) -> A;
fn find<F>(&'r self, f: F) -> Option<&A>
where F: Fn(&A) -> bool;
fn all<F>(&'r self, f: F) -> bool
where F: Fn(&A) -> bool;
fn any<F>(&'r self, f: F) -> bool
where F: Fn(&A) -> bool;
fn filter<F>(&'r self, f: F) -> Self::M
where F: Fn(&A) -> bool;
fn is_empty(&'r self) -> bool;
// Provided methods
fn concat(&'r self) -> A
where A: Monoid { ... }
fn non_empty(&'r self) -> bool { ... }
}Expand description
FoladableA is for endo type functions
Required Methods§
Sourcefn fold<F>(&'r self, z: A, f: F) -> A
fn fold<F>(&'r self, z: A, f: F) -> A
Reduces the values of the Foldable into a single value
§Examples
use funlib::Foldable::*;
let v = vec![1,2,3,4];
let sum = v.fold(0, |b, a| a + b);
assert_eq!(10, sum);Sourcefn find<F>(&'r self, f: F) -> Option<&A>
fn find<F>(&'r self, f: F) -> Option<&A>
Find a value in the foldable, returns an Option<&_>
§Examples
use funlib::Foldable::*;
let v = vec![1,2,3,4];
let s = v.find(|&a| a == 2);
let n = v.find(|&a| a == 5);
assert_eq!(Some(&2), s);
assert_eq!(None, n);Sourcefn all<F>(&'r self, f: F) -> bool
fn all<F>(&'r self, f: F) -> bool
Check if all values in the foldable returns true for function f
§Examples
use funlib::Foldable::*;
let v = vec![1,2,3,4];
assert_eq!(true, v.all(|&a| a < 5));
assert_eq!(false, v.all(|&a| a < 4));Sourcefn any<F>(&'r self, f: F) -> bool
fn any<F>(&'r self, f: F) -> bool
Check if any valu ein the foldable returns true for function f
§Examples
use funlib::Foldable::*;
let v = vec![1,2,3,4];
assert_eq!(true, v.any(|&a| a == 4));
assert_eq!(false, v.any(|&a| a == 5));Provided Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".