@@ -42,8 +42,8 @@ isJust = maybe false (const true)
4242isNothing :: forall a . Maybe a -> Boolean
4343isNothing = maybe true (const false )
4444
45- -- | The `Functor` instance for `Maybe` allows functions to transform the
46- -- | contents of a `Just` with the `<$>` operator:
45+ -- | The `Functor` instance allows functions to transform the contents of a
46+ -- | `Just` with the `<$>` operator:
4747-- |
4848-- | ``` purescript
4949-- | f <$> Just x == Just (f x)
@@ -58,8 +58,8 @@ instance functorMaybe :: Functor Maybe where
5858 (<$>) fn (Just x) = Just (fn x)
5959 (<$>) _ _ = Nothing
6060
61- -- | The `Apply` instance for `Maybe` allows functions contained within a `Just`
62- -- | to transform a value contained within a `Just` using the `(<*>)` operator:
61+ -- | The `Apply` instance allows functions contained within a `Just` to
62+ -- | transform a value contained within a `Just` using the `(<*>)` operator:
6363-- |
6464-- | ``` purescript
6565-- | Just f <*> Just x == Just (f x)
@@ -72,8 +72,9 @@ instance functorMaybe :: Functor Maybe where
7272-- | Nothing <$> Just x == Nothing
7373-- | ```
7474-- |
75- -- | Combining `Functor`'s' `<$>` with `Apply`'s `<*>` can be used to pass
76- -- | multiple `Maybe` values to a function that does not usually expect them:
75+ -- | Combining `Functor`'s' `<$>` with `Apply`'s `<*>` can be used transform a
76+ -- | pure function to take `Maybe`-typed arguments so `f :: a -> b -> c`
77+ -- | becomes `f :: Maybe a -> Maybe b -> Maybe c`:
7778-- |
7879-- | ``` purescript
7980-- | f <$> Just x <*> Just y == Just (f x y)
@@ -92,11 +93,12 @@ instance applyMaybe :: Apply Maybe where
9293 (<*>) (Just fn) x = fn <$> x
9394 (<*>) Nothing _ = Nothing
9495
95- -- | The `Applicative` instance for `Maybe` enables lifting of values into
96- -- | `Maybe` with the `pure ` function:
96+ -- | The `Applicative` instance enables lifting of values into `Maybe` with the
97+ -- | `pure` or `return ` function (`return` is an alias for `pure`) :
9798-- |
9899-- | ``` purescript
99100-- | pure x :: Maybe _ == Just x
101+ -- | return x :: Maybe _ == Just x
100102-- | ```
101103-- |
102104-- | Combining `Functor`'s' `<$>` with `Apply`'s `<*>` and `Applicative`'s
@@ -114,8 +116,8 @@ instance applyMaybe :: Apply Maybe where
114116instance applicativeMaybe :: Applicative Maybe where
115117 pure = Just
116118
117- -- | The `Alt` instance for `Maybe` allows for a choice to be made between two
118- -- | `Maybe` values with the `<|>` operator, where the first `Just` encountered
119+ -- | The `Alt` instance allows for a choice to be made between two `Maybe`
120+ -- | values with the `<|>` operator, where the first `Just` encountered
119121-- | is taken.
120122-- |
121123-- | ``` purescript
@@ -127,21 +129,20 @@ instance altMaybe :: Alt Maybe where
127129 (<|>) Nothing r = r
128130 (<|>) l _ = l
129131
130- -- | The `Plus` instance for `Maybe` enables a `Maybe` value to be constructed
131- -- | from no other values with the `empty` function:
132+ -- | The `Plus` instance provides a default `Maybe` value:
132133-- |
133134-- | ``` purescript
134135-- | empty :: Maybe _ == Nothing
135136-- | ```
136137instance plusMaybe :: Plus Maybe where
137138 empty = Nothing
138139
139- -- | The `Alternative` instance for `Maybe` guarantees that there are both
140- -- | `Applicative` and ` Plus` instances for `Maybe`.
140+ -- | The `Alternative` instance guarantees that there are both `Applicative` and
141+ -- | `Plus` instances for `Maybe`.
141142instance alternativeMaybe :: Alternative Maybe
142143
143- -- | The `Bind` instance for `Maybe` allows sequencing of `Maybe` values and
144- -- | functions that return a `Maybe` by using the `>>=` operator:
144+ -- | The `Bind` instance allows sequencing of `Maybe` values and functions that
145+ -- | return a `Maybe` by using the `>>=` operator:
145146-- |
146147-- | ``` purescript
147148-- | Just x >>= f = f x
@@ -151,10 +152,31 @@ instance bindMaybe :: Bind Maybe where
151152 (>>=) (Just x) k = k x
152153 (>>=) Nothing _ = Nothing
153154
155+ -- | The `Monad` instance guarantees that there are both `Applicative` and
156+ -- | `Bind` instances for `Maybe`. This also enables the `do` syntactic sugar:
157+ -- |
158+ -- | ``` purescript
159+ -- | do
160+ -- | x' <- x
161+ -- | y' <- y
162+ -- | pure (f x' y')
163+ -- | ```
164+ -- |
165+ -- | Which is equivalent to:
166+ -- |
167+ -- | ``` purescript
168+ -- | x >>= (\x' -> y >>= (\y' -> pure (f x' y')))
169+ -- | ```
154170instance monadMaybe :: Monad Maybe
155171
172+ -- | The `MonadPlus` instance guarantees that there are both `Monad` and
173+ -- | `Alternative` instances for `Maybe`.
156174instance monadPlusMaybe :: MonadPlus Maybe
157175
176+ -- | The `Extend` instance allows sequencing of `Maybe` values and functions
177+ -- | that accept a `Maybe a` and return a non-`Maybe` result using the
178+ -- | `<<=` operator.
179+ -- |
158180-- | ``` purescript
159181-- | f <<= Nothing = Nothing
160182-- | f <<= Just x = Just (f x)
@@ -163,6 +185,11 @@ instance extendMaybe :: Extend Maybe where
163185 (<<=) _ Nothing = Nothing
164186 (<<=) f x = Just (f x)
165187
188+ -- | The `Semigroup` instance enables use of the operator `<>` on `Maybe` values
189+ -- | whenever there is a `Semigroup` instance for the type the `Maybe` contains.
190+ -- | The exact behaviour of `<>` depends on the "inner" `Semigroup` instance,
191+ -- | but generally captures the notion of appending or combining things.
192+ -- |
166193-- | ``` purescript
167194-- | Just x <> Just y = Just (x <> y)
168195-- | Just x <> Nothing = Just x
@@ -174,6 +201,9 @@ instance semigroupMaybe :: (Semigroup a) => Semigroup (Maybe a) where
174201 (<>) x Nothing = x
175202 (<>) (Just x) (Just y) = Just (x <> y)
176203
204+ -- | The `Show` instance allows `Maybe` values to be rendered as a string with
205+ -- | `show` whenever there is an `Show` instance for the type the `Maybe`
206+ -- | contains.
177207instance showMaybe :: (Show a ) => Show (Maybe a ) where
178208 show (Just x) = " Just (" ++ show x ++ " )"
179209 show Nothing = " Nothing"
0 commit comments