sop-extras-0.2.1.0: Type-level and data utilities that build upon SOP.
Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.SOP.NonEmpty

Description

Type-level non-empty lists

Synopsis

Documentation

data NonEmpty xs a where Source #

Non-empty variation on AtMost

Constructors

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

Instances

Instances details
Foldable (NonEmpty xs) Source # 
Instance details

Defined in Data.SOP.NonEmpty

Methods

foldMonoid m ⇒ NonEmpty xs m → m #

foldMapMonoid 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 #

toListNonEmpty xs a → [a] #

nullNonEmpty xs a → Bool #

lengthNonEmpty xs a → Int #

elemEq a ⇒ a → NonEmpty xs a → Bool #

maximumOrd a ⇒ NonEmpty xs a → a #

minimumOrd a ⇒ NonEmpty xs a → a #

sumNum a ⇒ NonEmpty xs a → a #

productNum a ⇒ NonEmpty xs a → a #

Traversable (NonEmpty xs) Source # 
Instance details

Defined in Data.SOP.NonEmpty

Methods

traverseApplicative f ⇒ (a → f b) → NonEmpty xs a → f (NonEmpty xs b) #

sequenceAApplicative f ⇒ NonEmpty xs (f a) → f (NonEmpty xs a) #

mapMMonad m ⇒ (a → m b) → NonEmpty xs a → m (NonEmpty xs b) #

sequenceMonad m ⇒ NonEmpty xs (m a) → m (NonEmpty xs a) #

(IsNonEmpty xs, SListI xs) ⇒ Applicative (NonEmpty xs) Source # 
Instance details

Defined in Data.SOP.NonEmpty

Methods

pure ∷ a → NonEmpty xs a #

(<*>)NonEmpty xs (a → b) → NonEmpty xs a → NonEmpty xs b #

liftA2 ∷ (a → b → c) → NonEmpty xs a → NonEmpty xs b → NonEmpty xs c #

(*>)NonEmpty xs a → NonEmpty xs b → NonEmpty xs b #

(<*)NonEmpty xs a → NonEmpty xs b → NonEmpty xs a #

Functor (NonEmpty xs) Source # 
Instance details

Defined in Data.SOP.NonEmpty

Methods

fmap ∷ (a → b) → NonEmpty xs a → NonEmpty xs b #

(<$) ∷ a → NonEmpty xs b → NonEmpty xs a #

Show a ⇒ Show (NonEmpty xs a) Source # 
Instance details

Defined in Data.SOP.NonEmpty

Methods

showsPrecIntNonEmpty xs a → ShowS #

showNonEmpty xs a → String #

showList ∷ [NonEmpty xs a] → ShowS #

Eq a ⇒ Eq (NonEmpty xs a) Source # 
Instance details

Defined in Data.SOP.NonEmpty

Methods

(==)NonEmpty xs a → NonEmpty xs a → Bool #

(/=)NonEmpty xs a → NonEmpty xs a → Bool #

Proofs

class IsNonEmpty xs where Source #

Methods

isNonEmpty ∷ proxy xs → ProofNonEmpty xs Source #

Instances

Instances details
IsNonEmpty (x ': xs ∷ [a]) Source # 
Instance details

Defined in Data.SOP.NonEmpty

Methods

isNonEmpty ∷ proxy (x ': xs) → ProofNonEmpty (x ': xs) Source #

data ProofNonEmpty xs where Source #

Constructors

ProofNonEmptyProxy x → Proxy xs → ProofNonEmpty (x ': xs) 

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

Working with NonEmpty

nonEmptyFromList ∷ ∀ xs a. SListI xs ⇒ [a] → Maybe (NonEmpty xs a) Source #

Build a NonEmpty from a list. Returns Nothing when the list is empty or when it's longer than xs.

nonEmptyHeadNonEmpty xs a → a Source #

Analogue of head

nonEmptyInitNonEmpty xs a → (Maybe (NonEmpty xs a), a) Source #

Analogue of init

nonEmptyLastNonEmpty 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

nonEmptyStrictPrefixesNonEmpty 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.