From 90c1087291e0cfb9c5ac654ee47fc7d8a3c2b145 Mon Sep 17 00:00:00 2001 From: Gary Burgess Date: Fri, 1 Jul 2016 13:07:39 +0100 Subject: [PATCH] Add generic instance --- bower.json | 3 ++- src/Data/NonEmpty.purs | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/bower.json b/bower.json index 3c007ca..270b7e4 100644 --- a/bower.json +++ b/bower.json @@ -16,7 +16,8 @@ "url": "git://github.com/paf31/purescript-nonempty.git" }, "dependencies": { - "purescript-foldable-traversable": "^1.0.0" + "purescript-foldable-traversable": "^1.0.0", + "purescript-generics": "^1.0.0" }, "devDependencies": { "purescript-console": "^1.0.0", diff --git a/src/Data/NonEmpty.purs b/src/Data/NonEmpty.purs index 36bfcc9..edde167 100644 --- a/src/Data/NonEmpty.purs +++ b/src/Data/NonEmpty.purs @@ -21,6 +21,7 @@ import Control.Alternative (class Alternative) import Control.Plus (class Plus, empty) import Data.Foldable (class Foldable, foldl, foldr, foldMap) +import Data.Generic (class Generic) import Data.Traversable (class Traversable, traverse, sequence) -- | A non-empty container of elements of type a. @@ -78,6 +79,8 @@ instance ordNonEmpty :: (Ord a, Ord (f a)) => Ord (NonEmpty f a) where EQ -> compare fa1 fa2 other -> other +derive instance genericNonEmpty :: (Generic (f a), Generic a) => Generic (NonEmpty f a) + instance functorNonEmpty :: Functor f => Functor (NonEmpty f) where map f (a :| fa) = f a :| map f fa