Skip to content

Instantly share code, notes, and snippets.

@kolektiv
Created August 16, 2018 15:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kolektiv/3bb84c9fc8c32049eaeee0ffe550806c to your computer and use it in GitHub Desktop.
Save kolektiv/3bb84c9fc8c32049eaeee0ffe550806c to your computer and use it in GitHub Desktop.
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