cat/alternative

Alternative type {minimal implementation - empty and or}.
Default implementation for the fold function.

Types

Alternative type, a monoid on applicative functors.

class Applicative f => Alternative f where
empty :: f a
(<|>) :: f a -> f a -> f a

This type can be useful when working with operations that may fail/return no results

empty <|> a == a
a <|> empty == a
a <|> b == a
empty <|> empty == empty
pub type Alternative(f, fa) {
  Alternative(empty: fa, or: fn(fa, fa) -> fa)
}

Constructors

  • Alternative(empty: fa, or: fn(fa, fa) -> fa)

Values

pub fn fold(a: Alternative(f, fa), l: List(fa)) -> fa

Function used on a list of alternative values.

Examples

fold(option_alternative(), [None, None, Some(2), Some(3), None])
// -> Some(2)
fold(option_alternative(), [None, None, None])
// -> None
fold(option_alternative(), [])
// -> None
Search Document