Trait naan::alt::Plus

source ·
pub trait Plus<F, A>where
    Self: Alt<F, A>,
    F: HKT1<T<A> = Self>,{
    // Required method
    fn empty() -> F::T<A>;
}
Expand description

Plus adds an identity (empty) value to Alt.

Laws

The Plus identity value must be a no-op on either side of an alt, e.g.

use naan::prelude::*;

assert_eq!(Option::pure("hello").alt(Option::empty()),
           Option::pure("hello"));

// Generalized:
fn assert_empty_is_identity<F, A, T>(t: T)
  where T: PartialEq + core::fmt::Debug + Clone + Plus<F, A>,
        F: HKT1<T<A> = T>
{
  assert_eq!(t.clone().alt(T::empty()), t.clone());
  assert_eq!(T::empty().alt(t.clone()), t);
}

assert_empty_is_identity(Some("hello"));
assert_empty_is_identity(vec!["hello"]);

Required Methods§

source

fn empty() -> F::T<A>

See Plus

Implementations on Foreign Types§

source§

impl<A> Plus<Option, A> for Option<A>

source§

fn empty() -> <Option as HKT1>::T<A>

source§

impl<A> Plus<Vec, A> for Vec<A>

source§

fn empty() -> <Vec as HKT1>::T<A>

source§

impl<K, A> Plus<HashMapValues<K>, A> for HashMap<K, A>where K: Eq + Hash,

source§

fn empty() -> <HashMapValues<K> as HKT1>::T<A>

source§

impl<A, const N: usize> Plus<ArrayVec<N>, A> for ArrayVec<[Option<A>; N]>

source§

fn empty() -> Self

source§

impl<K, A> Plus<BTreeMapValues<K>, A> for BTreeMap<K, A>where K: Ord,

source§

fn empty() -> <BTreeMapValues<K> as HKT1>::T<A>

Implementors§