Skip to content

Instantly share code, notes, and snippets.

Created August 16, 2018 15:15
What would you like to do?
module Data.NonEmptyArray where
import Prelude
data NonEmpty a =
NonEmpty a (Array a)
instance showNonEmpty :: Show a => Show (NonEmpty a) where
show (NonEmpty a as) = "NonEmpty: " <> show a <> show as
instance eqNonEmpty :: Eq a => Eq (NonEmpty a) where
eq (NonEmpty a as) (NonEmpty b bs) | a == b && as == bs = true
eq _ _ = false
instance semigroupNonEmpty :: Semigroup (NonEmpty a) where
append (NonEmpty a as) (NonEmpty b bs) = NonEmpty a (as <> [ b ] <> bs)
instance functorNonEmpty :: Functor NonEmpty where
map f (NonEmpty a as) = NonEmpty (f a) (map f as)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment