Skip to content

Commit 47d634d

Browse files
committed
More doc layout revisions
1 parent 82a1f95 commit 47d634d

File tree

1 file changed

+83
-43
lines changed

1 file changed

+83
-43
lines changed

README.md

Lines changed: 83 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,22 @@
44

55
#### `Maybe`
66

7+
``` purescript
8+
data Maybe a
9+
= Nothing
10+
| Just a
11+
```
12+
713
The `Maybe` type is used to represent optional values and can be seen as
814
something like a type-safe `null`, where `Nothing` is `null` and `Just x`
915
is the non-null value `x`.
1016

11-
data Maybe a
12-
= Nothing
13-
| Just a
14-
1517
#### `maybe`
1618

19+
``` purescript
20+
maybe :: forall a b. b -> (a -> b) -> Maybe a -> b
21+
```
22+
1723
Takes a default value, a function, and a `Maybe` value. If the `Maybe`
1824
value is `Nothing` the default value is returned, otherwise the function
1925
is applied to the value inside the `Just` and the result is returned.
@@ -23,10 +29,12 @@ maybe default f Nothing == default
2329
maybe default f (Just x) == f x
2430
```
2531

26-
maybe :: forall a b. b -> (a -> b) -> Maybe a -> b
27-
2832
#### `fromMaybe`
2933

34+
``` purescript
35+
fromMaybe :: forall a. a -> Maybe a -> a
36+
```
37+
3038
Takes a default value, and a `Maybe` value. If the `Maybe` value is
3139
`Nothing` the default value is returned, otherwise the value inside the
3240
`Just` is returned.
@@ -36,22 +44,28 @@ fromMaybe default Nothing == default
3644
fromMaybe default (Just x) == x
3745
```
3846

39-
fromMaybe :: forall a. a -> Maybe a -> a
40-
4147
#### `isJust`
4248

43-
Returns `true` when the `Maybe` value was constructed with `Just`.
49+
``` purescript
50+
isJust :: forall a. Maybe a -> Boolean
51+
```
4452

45-
isJust :: forall a. Maybe a -> Boolean
53+
Returns `true` when the `Maybe` value was constructed with `Just`.
4654

4755
#### `isNothing`
4856

49-
Returns `true` when the `Maybe` value is `Nothing`.
57+
``` purescript
58+
isNothing :: forall a. Maybe a -> Boolean
59+
```
5060

51-
isNothing :: forall a. Maybe a -> Boolean
61+
Returns `true` when the `Maybe` value is `Nothing`.
5262

5363
#### `functorMaybe`
5464

65+
``` purescript
66+
instance functorMaybe :: Functor Maybe
67+
```
68+
5569
The `Functor` instance allows functions to transform the contents of a
5670
`Just` with the `<$>` operator:
5771

@@ -65,10 +79,12 @@ f <$> Just x == Just (f x)
6579
f <$> Nothing == Nothing
6680
```
6781

68-
instance functorMaybe :: Functor Maybe
69-
7082
#### `applyMaybe`
7183

84+
``` purescript
85+
instance applyMaybe :: Apply Maybe
86+
```
87+
7288
The `Apply` instance allows functions contained within a `Just` to
7389
transform a value contained within a `Just` using the `(<*>)` operator:
7490

@@ -101,10 +117,12 @@ f <$> Just x <*> Nothing == Nothing
101117
f <$> Nothing <*> Nothing == Nothing
102118
```
103119

104-
instance applyMaybe :: Apply Maybe
105-
106120
#### `applicativeMaybe`
107121

122+
``` purescript
123+
instance applicativeMaybe :: Applicative Maybe
124+
```
125+
108126
The `Applicative` instance enables lifting of values into `Maybe` with the
109127
`pure` or `return` function (`return` is an alias for `pure`):
110128

@@ -126,10 +144,12 @@ Even though `pure = Just` it is recommended to use `pure` in situations
126144
like this as it allows the choice of `Applicative` to be changed later
127145
without having to go through and replace `Just` with a new constructor.
128146

129-
instance applicativeMaybe :: Applicative Maybe
130-
131147
#### `altMaybe`
132148

149+
``` purescript
150+
instance altMaybe :: Alt Maybe
151+
```
152+
133153
The `Alt` instance allows for a choice to be made between two `Maybe`
134154
values with the `<|>` operator, where the first `Just` encountered
135155
is taken.
@@ -140,27 +160,33 @@ Nothing <|> Just y == Just y
140160
Nothing <|> Nothing == Nothing
141161
```
142162

143-
instance altMaybe :: Alt Maybe
144-
145163
#### `plusMaybe`
146164

165+
``` purescript
166+
instance plusMaybe :: Plus Maybe
167+
```
168+
147169
The `Plus` instance provides a default `Maybe` value:
148170

149171
``` purescript
150172
empty :: Maybe _ == Nothing
151173
```
152174

153-
instance plusMaybe :: Plus Maybe
154-
155175
#### `alternativeMaybe`
156176

177+
``` purescript
178+
instance alternativeMaybe :: Alternative Maybe
179+
```
180+
157181
The `Alternative` instance guarantees that there are both `Applicative` and
158182
`Plus` instances for `Maybe`.
159183

160-
instance alternativeMaybe :: Alternative Maybe
161-
162184
#### `bindMaybe`
163185

186+
``` purescript
187+
instance bindMaybe :: Bind Maybe
188+
```
189+
164190
The `Bind` instance allows sequencing of `Maybe` values and functions that
165191
return a `Maybe` by using the `>>=` operator:
166192

@@ -169,10 +195,12 @@ Just x >>= f = f x
169195
Nothing >>= f = Nothing
170196
```
171197

172-
instance bindMaybe :: Bind Maybe
173-
174198
#### `monadMaybe`
175199

200+
``` purescript
201+
instance monadMaybe :: Monad Maybe
202+
```
203+
176204
The `Monad` instance guarantees that there are both `Applicative` and
177205
`Bind` instances for `Maybe`. This also enables the `do` syntactic sugar:
178206

@@ -189,17 +217,21 @@ Which is equivalent to:
189217
x >>= (\x' -> y >>= (\y' -> pure (f x' y')))
190218
```
191219

192-
instance monadMaybe :: Monad Maybe
193-
194220
#### `monadPlusMaybe`
195221

222+
``` purescript
223+
instance monadPlusMaybe :: MonadPlus Maybe
224+
```
225+
196226
The `MonadPlus` instance guarantees that there are both `Monad` and
197227
`Alternative` instances for `Maybe`.
198228

199-
instance monadPlusMaybe :: MonadPlus Maybe
200-
201229
#### `extendMaybe`
202230

231+
``` purescript
232+
instance extendMaybe :: Extend Maybe
233+
```
234+
203235
The `Extend` instance allows sequencing of `Maybe` values and functions
204236
that accept a `Maybe a` and return a non-`Maybe` result using the
205237
`<<=` operator.
@@ -209,10 +241,12 @@ f <<= Nothing = Nothing
209241
f <<= Just x = Just (f x)
210242
```
211243

212-
instance extendMaybe :: Extend Maybe
213-
214244
#### `semigroupMaybe`
215245

246+
``` purescript
247+
instance semigroupMaybe :: (Semigroup a) => Semigroup (Maybe a)
248+
```
249+
216250
The `Semigroup` instance enables use of the operator `<>` on `Maybe` values
217251
whenever there is a `Semigroup` instance for the type the `Maybe` contains.
218252
The exact behaviour of `<>` depends on the "inner" `Semigroup` instance,
@@ -225,41 +259,47 @@ Nothing <> Just y = Just y
225259
Nothing <> Nothing = Nothing
226260
```
227261

228-
instance semigroupMaybe :: (Semigroup a) => Semigroup (Maybe a)
229-
230262
#### `showMaybe`
231263

264+
``` purescript
265+
instance showMaybe :: (Show a) => Show (Maybe a)
266+
```
267+
232268
The `Show` instance allows `Maybe` values to be rendered as a string with
233269
`show` whenever there is an `Show` instance for the type the `Maybe`
234270
contains.
235271

236-
instance showMaybe :: (Show a) => Show (Maybe a)
237-
238272
#### `eqMaybe`
239273

274+
``` purescript
275+
instance eqMaybe :: (Eq a) => Eq (Maybe a)
276+
```
277+
240278
The `Eq` instance allows `Maybe` values to be checked for equality with
241279
`==` and inequality with `/=` whenever there is an `Eq` instance for the
242280
type the `Maybe` contains.
243281

244-
instance eqMaybe :: (Eq a) => Eq (Maybe a)
245-
246282
#### `ordMaybe`
247283

284+
``` purescript
285+
instance ordMaybe :: (Ord a) => Ord (Maybe a)
286+
```
287+
248288
The `Ord` instance allows `Maybe` values to be compared with
249289
`compare`, `>`, `>=`, `<` and `<=` whenever there is an `Ord` instance for
250290
the type the `Maybe` contains.
251291

252292
`Nothing` is considered to be less than any `Just` value.
253293

254-
instance ordMaybe :: (Ord a) => Ord (Maybe a)
255-
256294

257295
## Module Data.Maybe.Unsafe
258296

259297
#### `fromJust`
260298

299+
``` purescript
300+
fromJust :: forall a. Maybe a -> a
301+
```
302+
261303
A partial function that extracts the value from the `Just` data
262304
constructor. Passing `Nothing` to `fromJust` will throw an error at
263-
runtime.
264-
265-
fromJust :: forall a. Maybe a -> a
305+
runtime.

0 commit comments

Comments
 (0)