Trait naan::fold::FoldableOnce
source · pub trait FoldableOnce<F, A>where
F: HKT1<T<A> = Self>,{
// Required methods
fn fold1<B, BAB>(self, f: BAB, b: B) -> B
where BAB: F2Once<B, A, Ret = B>;
fn fold1_ref<'a, B, BAB>(&'a self, f: BAB, b: B) -> B
where BAB: F2Once<B, &'a A, Ret = B>,
A: 'a;
// Provided methods
fn get_or(self, a: A) -> A
where Self: Sized { ... }
fn get_or_default(self) -> A
where Self: Sized,
A: Default { ... }
}
Expand description
Foldable
, but specialized to know at compile-time
that the reducing function will only be called one time.
Required Methods§
Provided Methods§
sourcefn get_or(self, a: A) -> Awhere
Self: Sized,
fn get_or(self, a: A) -> Awhere Self: Sized,
Unwrap the data structure, using a provided default value if empty
use naan::prelude::*;
assert_eq!(Some("a").get_or("b"), "a");
assert_eq!(None.get_or("b"), "b");
sourcefn get_or_default(self) -> Awhere
Self: Sized,
A: Default,
fn get_or_default(self) -> Awhere Self: Sized, A: Default,
Unwrap the data structure, using Default::default
if empty
use naan::prelude::*;
assert_eq!(Some(format!("a")).get_or_default(), format!("a"));
assert_eq!(Option::<String>::None.get_or_default(), String::new());