Skip to content
Open
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
8 changes: 7 additions & 1 deletion src/Data/NonEmpty.purs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import Data.Ord (class Ord1, compare1)
import Data.Semigroup.Foldable as F1
import Data.Traversable (class Traversable, traverse, sequence)
import Data.TraversableWithIndex (class TraversableWithIndex, traverseWithIndex)
import Prelude as Prelude

-- | A non-empty container of elements of type a.
-- |
Expand Down Expand Up @@ -71,6 +72,11 @@ head (x :| _) = x
tail :: forall f a. NonEmpty f a -> f a
tail (_ :| xs) = xs

-- | Useful for functorish non-functors like `Set`.
-- > NonEmpty.map Set.map (_ + 1)
map :: forall a b f. ((a -> b) -> f a -> f b) -> (a -> b) -> NonEmpty f a -> NonEmpty f b
map mapper f (a :| as) = (f a :| mapper f as)

instance showNonEmpty :: (Show a, Show (f a)) => Show (NonEmpty f a) where
show (a :| fa) = "(NonEmpty " <> show a <> " " <> show fa <> ")"

Expand All @@ -90,7 +96,7 @@ instance ord1NonEmpty :: Ord1 f => Ord1 (NonEmpty f) where
c -> c

instance functorNonEmpty :: Functor f => Functor (NonEmpty f) where
map f (a :| fa) = f a :| map f fa
map f (a :| fa) = f a :| Prelude.map f fa

instance functorWithIndex
:: FunctorWithIndex i f
Expand Down