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§

source

fn fold1<B, BAB>(self, f: BAB, b: B) -> Bwhere BAB: F2Once<B, A, Ret = B>,

Fold the data structure

source

fn fold1_ref<'a, B, BAB>(&'a self, f: BAB, b: B) -> Bwhere BAB: F2Once<B, &'a A, Ret = B>, A: 'a,

Fold the data structure

Provided Methods§

source

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");
source

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());

Implementations on Foreign Types§

source§

impl<A, E> FoldableOnce<ResultOk<E>, A> for Result<A, E>

source§

fn fold1<B, BAB>(self, f: BAB, b: B) -> Bwhere BAB: F2Once<B, A, Ret = B>,

source§

fn fold1_ref<'a, B, BAB>(&'a self, f: BAB, b: B) -> Bwhere BAB: F2Once<B, &'a A, Ret = B>, A: 'a,

source§

impl<A> FoldableOnce<Option, A> for Option<A>

source§

fn fold1<B, BAB>(self, f: BAB, b: B) -> Bwhere BAB: F2Once<B, A, Ret = B>,

source§

fn fold1_ref<'a, B, BAB>(&'a self, f: BAB, b: B) -> Bwhere BAB: F2Once<B, &'a A, Ret = B>, A: 'a,

Implementors§