Skip to content

Commit eecf17c

Browse files
committed
Add map function
1 parent 1d53fbd commit eecf17c

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/Data/NonEmpty.purs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ head (x :| _) = x
7171
tail :: forall f a. NonEmpty f a -> f a
7272
tail (_ :| xs) = xs
7373

74+
-- | Useful for functorish non-functors like `Set`.
75+
-- > NonEmpty.map Set.map (_ + 1)
76+
map :: forall a b f. ((a -> b) -> f a -> f b) -> (a -> b) -> NonEmpty f a -> NonEmpty f b
77+
map mapper f (a :| as) = (f a :| mapper f as)
78+
7479
instance showNonEmpty :: (Show a, Show (f a)) => Show (NonEmpty f a) where
7580
show (a :| fa) = "(NonEmpty " <> show a <> " " <> show fa <> ")"
7681

0 commit comments

Comments
 (0)