Skip to content

Commit 82a1f95

Browse files
committed
Restructured readme from new psc-docs
1 parent d494abd commit 82a1f95

File tree

1 file changed

+95
-105
lines changed

1 file changed

+95
-105
lines changed

README.md

Lines changed: 95 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
## Module Data.Maybe
44

5-
### Types
6-
75
#### `Maybe`
86

97
The `Maybe` type is used to represent optional values and can be seen as
@@ -14,54 +12,60 @@ is the non-null value `x`.
1412
= Nothing
1513
| Just a
1614

15+
#### `maybe`
1716

18-
### Type Class Instances
17+
Takes a default value, a function, and a `Maybe` value. If the `Maybe`
18+
value is `Nothing` the default value is returned, otherwise the function
19+
is applied to the value inside the `Just` and the result is returned.
1920

20-
#### `altMaybe`
21+
``` purescript
22+
maybe default f Nothing == default
23+
maybe default f (Just x) == f x
24+
```
2125

22-
The `Alt` instance allows for a choice to be made between two `Maybe`
23-
values with the `<|>` operator, where the first `Just` encountered
24-
is taken.
26+
maybe :: forall a b. b -> (a -> b) -> Maybe a -> b
27+
28+
#### `fromMaybe`
29+
30+
Takes a default value, and a `Maybe` value. If the `Maybe` value is
31+
`Nothing` the default value is returned, otherwise the value inside the
32+
`Just` is returned.
2533

2634
``` purescript
27-
Just x <|> Just y == Just x
28-
Nothing <|> Just y == Just y
29-
Nothing <|> Nothing == Nothing
35+
fromMaybe default Nothing == default
36+
fromMaybe default (Just x) == x
3037
```
3138

32-
instance altMaybe :: Alt Maybe
39+
fromMaybe :: forall a. a -> Maybe a -> a
3340

34-
#### `alternativeMaybe`
41+
#### `isJust`
3542

36-
The `Alternative` instance guarantees that there are both `Applicative` and
37-
`Plus` instances for `Maybe`.
43+
Returns `true` when the `Maybe` value was constructed with `Just`.
3844

39-
instance alternativeMaybe :: Alternative Maybe
45+
isJust :: forall a. Maybe a -> Boolean
4046

41-
#### `applicativeMaybe`
47+
#### `isNothing`
4248

43-
The `Applicative` instance enables lifting of values into `Maybe` with the
44-
`pure` or `return` function (`return` is an alias for `pure`):
49+
Returns `true` when the `Maybe` value is `Nothing`.
50+
51+
isNothing :: forall a. Maybe a -> Boolean
52+
53+
#### `functorMaybe`
54+
55+
The `Functor` instance allows functions to transform the contents of a
56+
`Just` with the `<$>` operator:
4557

4658
``` purescript
47-
pure x :: Maybe _ == Just x
48-
return x :: Maybe _ == Just x
59+
f <$> Just x == Just (f x)
4960
```
5061

51-
Combining `Functor`'s' `<$>` with `Apply`'s `<*>` and `Applicative`'s
52-
`pure` can be used to pass a mixture of `Maybe` and non-`Maybe` typed
53-
values to a function that does not usually expect them, by using `pure`
54-
for any value that is not already `Maybe` typed:
62+
`Nothing` values are left untouched:
5563

5664
``` purescript
57-
f <$> Just x <*> pure y == Just (f x y)
65+
f <$> Nothing == Nothing
5866
```
5967

60-
Even though `pure = Just` it is recommended to use `pure` in situations
61-
like this as it allows the choice of `Applicative` to be changed later
62-
without having to go through and replace `Just` with a new constructor.
63-
64-
instance applicativeMaybe :: Applicative Maybe
68+
instance functorMaybe :: Functor Maybe
6569

6670
#### `applyMaybe`
6771

@@ -99,55 +103,73 @@ f <$> Nothing <*> Nothing == Nothing
99103

100104
instance applyMaybe :: Apply Maybe
101105

102-
#### `bindMaybe`
106+
#### `applicativeMaybe`
103107

104-
The `Bind` instance allows sequencing of `Maybe` values and functions that
105-
return a `Maybe` by using the `>>=` operator:
108+
The `Applicative` instance enables lifting of values into `Maybe` with the
109+
`pure` or `return` function (`return` is an alias for `pure`):
106110

107111
``` purescript
108-
Just x >>= f = f x
109-
Nothing >>= f = Nothing
112+
pure x :: Maybe _ == Just x
113+
return x :: Maybe _ == Just x
110114
```
111115

112-
instance bindMaybe :: Bind Maybe
116+
Combining `Functor`'s' `<$>` with `Apply`'s `<*>` and `Applicative`'s
117+
`pure` can be used to pass a mixture of `Maybe` and non-`Maybe` typed
118+
values to a function that does not usually expect them, by using `pure`
119+
for any value that is not already `Maybe` typed:
113120

114-
#### `eqMaybe`
121+
``` purescript
122+
f <$> Just x <*> pure y == Just (f x y)
123+
```
115124

116-
The `Eq` instance allows `Maybe` values to be checked for equality with
117-
`==` and inequality with `/=` whenever there is an `Eq` instance for the
118-
type the `Maybe` contains.
125+
Even though `pure = Just` it is recommended to use `pure` in situations
126+
like this as it allows the choice of `Applicative` to be changed later
127+
without having to go through and replace `Just` with a new constructor.
119128

120-
instance eqMaybe :: (Eq a) => Eq (Maybe a)
129+
instance applicativeMaybe :: Applicative Maybe
121130

122-
#### `extendMaybe`
131+
#### `altMaybe`
123132

124-
The `Extend` instance allows sequencing of `Maybe` values and functions
125-
that accept a `Maybe a` and return a non-`Maybe` result using the
126-
`<<=` operator.
133+
The `Alt` instance allows for a choice to be made between two `Maybe`
134+
values with the `<|>` operator, where the first `Just` encountered
135+
is taken.
127136

128137
``` purescript
129-
f <<= Nothing = Nothing
130-
f <<= Just x = Just (f x)
138+
Just x <|> Just y == Just x
139+
Nothing <|> Just y == Just y
140+
Nothing <|> Nothing == Nothing
131141
```
132142

133-
instance extendMaybe :: Extend Maybe
143+
instance altMaybe :: Alt Maybe
134144

135-
#### `functorMaybe`
145+
#### `plusMaybe`
136146

137-
The `Functor` instance allows functions to transform the contents of a
138-
`Just` with the `<$>` operator:
147+
The `Plus` instance provides a default `Maybe` value:
139148

140149
``` purescript
141-
f <$> Just x == Just (f x)
150+
empty :: Maybe _ == Nothing
142151
```
143152

144-
`Nothing` values are left untouched:
153+
instance plusMaybe :: Plus Maybe
154+
155+
#### `alternativeMaybe`
156+
157+
The `Alternative` instance guarantees that there are both `Applicative` and
158+
`Plus` instances for `Maybe`.
159+
160+
instance alternativeMaybe :: Alternative Maybe
161+
162+
#### `bindMaybe`
163+
164+
The `Bind` instance allows sequencing of `Maybe` values and functions that
165+
return a `Maybe` by using the `>>=` operator:
145166

146167
``` purescript
147-
f <$> Nothing == Nothing
168+
Just x >>= f = f x
169+
Nothing >>= f = Nothing
148170
```
149171

150-
instance functorMaybe :: Functor Maybe
172+
instance bindMaybe :: Bind Maybe
151173

152174
#### `monadMaybe`
153175

@@ -176,25 +198,18 @@ The `MonadPlus` instance guarantees that there are both `Monad` and
176198

177199
instance monadPlusMaybe :: MonadPlus Maybe
178200

179-
#### `ordMaybe`
180-
181-
The `Ord` instance allows `Maybe` values to be compared with
182-
`compare`, `>`, `>=`, `<` and `<=` whenever there is an `Ord` instance for
183-
the type the `Maybe` contains.
184-
185-
`Nothing` is considered to be less than any `Just` value.
186-
187-
instance ordMaybe :: (Ord a) => Ord (Maybe a)
188-
189-
#### `plusMaybe`
201+
#### `extendMaybe`
190202

191-
The `Plus` instance provides a default `Maybe` value:
203+
The `Extend` instance allows sequencing of `Maybe` values and functions
204+
that accept a `Maybe a` and return a non-`Maybe` result using the
205+
`<<=` operator.
192206

193207
``` purescript
194-
empty :: Maybe _ == Nothing
208+
f <<= Nothing = Nothing
209+
f <<= Just x = Just (f x)
195210
```
196211

197-
instance plusMaybe :: Plus Maybe
212+
instance extendMaybe :: Extend Maybe
198213

199214
#### `semigroupMaybe`
200215

@@ -220,52 +235,27 @@ contains.
220235

221236
instance showMaybe :: (Show a) => Show (Maybe a)
222237

238+
#### `eqMaybe`
223239

224-
### Values
225-
226-
#### `fromMaybe`
227-
228-
Takes a default value, and a `Maybe` value. If the `Maybe` value is
229-
`Nothing` the default value is returned, otherwise the value inside the
230-
`Just` is returned.
231-
232-
``` purescript
233-
fromMaybe default Nothing == default
234-
fromMaybe default (Just x) == x
235-
```
236-
237-
fromMaybe :: forall a. a -> Maybe a -> a
238-
239-
#### `isJust`
240-
241-
Returns `true` when the `Maybe` value was constructed with `Just`.
242-
243-
isJust :: forall a. Maybe a -> Boolean
244-
245-
#### `isNothing`
246-
247-
Returns `true` when the `Maybe` value is `Nothing`.
240+
The `Eq` instance allows `Maybe` values to be checked for equality with
241+
`==` and inequality with `/=` whenever there is an `Eq` instance for the
242+
type the `Maybe` contains.
248243

249-
isNothing :: forall a. Maybe a -> Boolean
244+
instance eqMaybe :: (Eq a) => Eq (Maybe a)
250245

251-
#### `maybe`
246+
#### `ordMaybe`
252247

253-
Takes a default value, a function, and a `Maybe` value. If the `Maybe`
254-
value is `Nothing` the default value is returned, otherwise the function
255-
is applied to the value inside the `Just` and the result is returned.
248+
The `Ord` instance allows `Maybe` values to be compared with
249+
`compare`, `>`, `>=`, `<` and `<=` whenever there is an `Ord` instance for
250+
the type the `Maybe` contains.
256251

257-
``` purescript
258-
maybe default f Nothing == default
259-
maybe default f (Just x) == f x
260-
```
252+
`Nothing` is considered to be less than any `Just` value.
261253

262-
maybe :: forall a b. b -> (a -> b) -> Maybe a -> b
254+
instance ordMaybe :: (Ord a) => Ord (Maybe a)
263255

264256

265257
## Module Data.Maybe.Unsafe
266258

267-
### Values
268-
269259
#### `fromJust`
270260

271261
A partial function that extracts the value from the `Just` data

0 commit comments

Comments
 (0)