Skip to content

Commit d3d1296

Browse files
committed
Merge pull request #5 from joneshf/master
Add `Extend` and `Semigroup` instances.
2 parents 9033b04 + b94710a commit d3d1296

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323

2424
instance eqMaybe :: (Eq a) => Eq (Maybe a)
2525

26+
instance extendMaybe :: Extend Maybe
27+
2628
instance functorMaybe :: Functor Maybe
2729

2830
instance monadMaybe :: Monad Maybe
@@ -33,6 +35,8 @@
3335

3436
instance plusMaybe :: Plus Maybe
3537

38+
instance semigroupMaybe :: (Semigroup a) => Semigroup (Maybe a)
39+
3640
instance showMaybe :: (Show a) => Show (Maybe a)
3741

3842

src/Data/Maybe.purs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
module Data.Maybe where
22

33
import Control.Alt
4-
import Control.Plus
54
import Control.Alternative
5+
import Control.Extend
66
import Control.MonadPlus
7+
import Control.Plus
78

89
data Maybe a = Nothing | Just a
910

@@ -48,6 +49,15 @@ instance monadMaybe :: Monad Maybe
4849

4950
instance monadPlusMaybe :: MonadPlus Maybe
5051

52+
instance extendMaybe :: Extend Maybe where
53+
(<<=) _ Nothing = Nothing
54+
(<<=) f x = Just $ f x
55+
56+
instance semigroupMaybe :: (Semigroup a) => Semigroup (Maybe a) where
57+
(<>) Nothing x = x
58+
(<>) x Nothing = x
59+
(<>) (Just x) (Just y) = Just (x <> y)
60+
5161
instance showMaybe :: (Show a) => Show (Maybe a) where
5262
show (Just x) = "Just (" ++ show x ++ ")"
5363
show Nothing = "Nothing"

0 commit comments

Comments
 (0)