Skip to content
Closed
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions src/Data/NonEmpty.purs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
1 change: 1 addition & 0 deletions test/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -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]