Safe Haskell | Safe-Inferred |
---|---|

Language | Haskell2010 |

Type-level non-empty lists

## Synopsis

- data NonEmpty xs a where
- NonEmptyOne ∷ !a → NonEmpty (x ': xs) a
- NonEmptyCons ∷ !a → !(NonEmpty xs a) → NonEmpty (x ': xs) a

- class IsNonEmpty xs where
- isNonEmpty ∷ proxy xs → ProofNonEmpty xs

- data ProofNonEmpty xs where
- ProofNonEmpty ∷ Proxy x → Proxy xs → ProofNonEmpty (x ': xs)

- checkIsNonEmpty ∷ ∀ xs. SListI xs ⇒ Proxy xs → Maybe (ProofNonEmpty xs)
- nonEmptyFromList ∷ ∀ xs a. SListI xs ⇒ [a] → Maybe (NonEmpty xs a)
- nonEmptyHead ∷ NonEmpty xs a → a
- nonEmptyInit ∷ NonEmpty xs a → (Maybe (NonEmpty xs a), a)
- nonEmptyLast ∷ NonEmpty xs a → a
- nonEmptyMapOne ∷ ∀ m xs a. Alternative m ⇒ (a → m a) → NonEmpty xs a → m (NonEmpty xs a)
- nonEmptyMapTwo ∷ ∀ m xs a. Alternative m ⇒ (a → m a) → (a → a → m (a, a)) → NonEmpty xs a → m (NonEmpty xs a)
- nonEmptyStrictPrefixes ∷ NonEmpty xs a → [NonEmpty xs a]
- nonEmptyToList ∷ ∀ xs a. NonEmpty xs a → [a]

# Documentation

data NonEmpty xs a where Source #

Non-empty variation on `AtMost`

NonEmptyOne ∷ !a → NonEmpty (x ': xs) a | |

NonEmptyCons ∷ !a → !(NonEmpty xs a) → NonEmpty (x ': xs) a |

#### Instances

Foldable (NonEmpty xs) Source # | |

Defined in Data.SOP.NonEmpty fold ∷ Monoid m ⇒ NonEmpty xs m → m # foldMap ∷ Monoid m ⇒ (a → m) → NonEmpty xs a → m # foldMap' ∷ Monoid m ⇒ (a → m) → NonEmpty xs a → m # foldr ∷ (a → b → b) → b → NonEmpty xs a → b # foldr' ∷ (a → b → b) → b → NonEmpty xs a → b # foldl ∷ (b → a → b) → b → NonEmpty xs a → b # foldl' ∷ (b → a → b) → b → NonEmpty xs a → b # foldr1 ∷ (a → a → a) → NonEmpty xs a → a # foldl1 ∷ (a → a → a) → NonEmpty xs a → a # toList ∷ NonEmpty xs a → [a] # length ∷ NonEmpty xs a → Int # elem ∷ Eq a ⇒ a → NonEmpty xs a → Bool # maximum ∷ Ord a ⇒ NonEmpty xs a → a # minimum ∷ Ord a ⇒ NonEmpty xs a → a # | |

Traversable (NonEmpty xs) Source # | |

(IsNonEmpty xs, SListI xs) ⇒ Applicative (NonEmpty xs) Source # | |

Functor (NonEmpty xs) Source # | |

Show a ⇒ Show (NonEmpty xs a) Source # | |

Eq a ⇒ Eq (NonEmpty xs a) Source # | |

# Proofs

class IsNonEmpty xs where Source #

isNonEmpty ∷ proxy xs → ProofNonEmpty xs Source #

#### Instances

IsNonEmpty (x ': xs ∷ [a]) Source # | |

Defined in Data.SOP.NonEmpty isNonEmpty ∷ proxy (x ': xs) → ProofNonEmpty (x ': xs) Source # |

data ProofNonEmpty xs where Source #

ProofNonEmpty ∷ Proxy x → Proxy xs → ProofNonEmpty (x ': xs) |

checkIsNonEmpty ∷ ∀ xs. SListI xs ⇒ Proxy xs → Maybe (ProofNonEmpty xs) Source #

# Working with `NonEmpty`

nonEmptyHead ∷ NonEmpty xs a → a Source #

Analogue of `head`

nonEmptyLast ∷ NonEmpty xs a → a Source #

Analogue of `last`

nonEmptyMapOne ∷ ∀ m xs a. Alternative m ⇒ (a → m a) → NonEmpty xs a → m (NonEmpty xs a) Source #

Apply the specified function to exactly one element

nonEmptyMapTwo ∷ ∀ m xs a. Alternative m ⇒ (a → m a) → (a → a → m (a, a)) → NonEmpty xs a → m (NonEmpty xs a) Source #

Variation on `nonEmptyMapOne`

where we try to apply the function to
*pairs* of elements

nonEmptyStrictPrefixes ∷ NonEmpty xs a → [NonEmpty xs a] Source #

A strict prefixes

nonEmptyStrictPrefixes (fromJust (nonEmptyFromList [1..4])) == [ NonEmptyOne 1 , NonEmptyCons 1 $ NonEmptyOne 2 , NonEmptyCons 1 $ NonEmptyCons 2 $ NonEmptyOne 3 ]

nonEmptyToList ∷ ∀ xs a. NonEmpty xs a → [a] Source #

Convert a `NonEmpty`

to a list.