diff --git a/src/Data/NonEmpty.purs b/src/Data/NonEmpty.purs index edde167..165ac63 100644 --- a/src/Data/NonEmpty.purs +++ b/src/Data/NonEmpty.purs @@ -92,3 +92,6 @@ instance foldableNonEmpty :: Foldable f => Foldable (NonEmpty f) where instance traversableNonEmpty :: Traversable f => Traversable (NonEmpty f) where sequence (a :| fa) = NonEmpty <$> a <*> sequence fa traverse f (a :| fa) = NonEmpty <$> f a <*> traverse f fa + +instance semigroupNonEmpty :: Alternative f => Semigroup (NonEmpty f a) where + append (a :| fa) (b :| fb) = NonEmpty a (fa <|> pure b <|> fb) diff --git a/test/Main.purs b/test/Main.purs index 20b2ab2..b59275d 100644 --- a/test/Main.purs +++ b/test/Main.purs @@ -23,3 +23,4 @@ main = do assert $ fold ("Hello" :| [" ", "World"]) == "Hello World" assert $ oneOf (0 :| Nothing) == oneOf (0 :| Just 1) assert $ second (1 :| 2 :| [3, 4]) == 2 + assert $ (1 :| [2, 3]) <> (4 :| [5,6]) == 1 :| [2, 3, 4, 5, 6]