Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/Data/NonEmpty.purs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import Prelude

import Control.Alt ((<|>))
import Control.Alternative (class Alternative)
import Control.Comonad (class Comonad)
import Control.Extend (class Extend)
import Control.Plus (class Plus, empty)

import Data.Foldable (class Foldable, foldl, foldr, foldMap)
Expand Down Expand Up @@ -84,6 +86,13 @@ derive instance genericNonEmpty :: (Generic (f a), Generic a) => Generic (NonEmp
instance functorNonEmpty :: Functor f => Functor (NonEmpty f) where
map f (a :| fa) = f a :| map f fa

instance extendNonEmpty :: (Functor f, Plus f) => Extend (NonEmpty f) where
extend f (a :| fa) =
NonEmpty (f (NonEmpty a empty)) (map (\x -> f (NonEmpty x empty)) fa)

instance comonadNonEmpty :: (Functor f, Plus f) => Comonad (NonEmpty f) where
extract (a :| _) = a

instance foldableNonEmpty :: Foldable f => Foldable (NonEmpty f) where
foldMap f (a :| fa) = f a <> foldMap f fa
foldl f b (a :| fa) = foldl f (f b a) fa
Expand Down