@@ -94,20 +94,24 @@ post =
94
94
95
95
postEdit :: Match MyRoute
96
96
postEdit =
97
- PostEdit <$> (lit "posts" *> int <* lit "edit")
97
+ PostEdit <$> (lit "posts" *> int) <* lit "edit"
98
98
```
99
99
100
100
Note the use of the ` *> ` and ` <* ` operators. These let us direct the focus of
101
101
the value we want to consume. In ` postEdit ` , we want to consume the ` int ` ,
102
102
but we also need to match the "edit" suffix. The arrows point to the value we
103
103
want.
104
104
105
+ Note that in general parentheses are required when using ` *> ` since the
106
+ operator precedence is not what is required (resulting in type errors
107
+ otherwise.)
108
+
105
109
And now finally, we need to extract multiple segments for ` PostBrowse ` .
106
110
107
111
``` purescript
108
112
postBrowse :: Match MyRoute
109
113
postBrowse =
110
- PostBrowse <$> (lit "posts" *> str <*> str)
114
+ PostBrowse <$> (lit "posts" *> str) <*> str
111
115
```
112
116
113
117
The ` <*> ` combinator has arrows on both sides because we want both values.
@@ -145,8 +149,8 @@ myRoute :: Match MyRoute
145
149
myRoute = oneOf
146
150
[ PostIndex <$ lit "posts"
147
151
, Post <$> (lit "posts" *> int)
148
- , PostEdit <$> (lit "posts" *> int <* lit "edit")
149
- , PostBrowse <$> (lit "posts" *> str <*> str)
152
+ , PostEdit <$> (lit "posts" *> int) <* lit "edit"
153
+ , PostBrowse <$> (lit "posts" *> str) <*> str
150
154
]
151
155
```
152
156
@@ -161,8 +165,8 @@ myRoute =
161
165
lit "posts" *> oneOf
162
166
[ pure PostIndex
163
167
, Post <$> int
164
- , PostEdit <$> ( int <* lit "edit")
165
- , PostBrowse <$> ( str <*> str)
168
+ , PostEdit <$> int <* lit "edit"
169
+ , PostBrowse <$> str <*> str
166
170
]
167
171
```
168
172
@@ -179,9 +183,9 @@ myRoute :: Match MyRoute
179
183
myRoute =
180
184
lit "posts" *> oneOf
181
185
[ PostIndex <$ end
182
- , Post <$> ( int <* end)
183
- , PostEdit <$> ( int <* lit "edit" <* end)
184
- , PostBrowse <$> ( str <*> str <* end)
186
+ , Post <$> int <* end
187
+ , PostEdit <$> int <* lit "edit" <* end
188
+ , PostBrowse <$> str <*> str <* end
185
189
]
186
190
```
187
191
@@ -193,9 +197,9 @@ the routes followed by an `end`, so we would still have to rearrange them.
193
197
myRoute :: Match MyRoute
194
198
myRoute =
195
199
lit "posts" *> oneOf
196
- [ PostEdit <$> ( int <* lit "edit")
200
+ [ PostEdit <$> int <* lit "edit"
197
201
, Post <$> int
198
- , PostBrowse <$> ( str <*> str)
202
+ , PostBrowse <$> str <*> str
199
203
, pure PostIndex
200
204
] <* end
201
205
```
@@ -211,9 +215,9 @@ with the `root` combinator.
211
215
myRoute :: Match MyRoute
212
216
myRoute =
213
217
root *> lit "posts" *> oneOf
214
- [ PostEdit <$> ( int <* lit "edit")
218
+ [ PostEdit <$> int <* lit "edit"
215
219
, Post <$> int
216
- , PostBrowse <$> ( str <*> str)
220
+ , PostBrowse <$> str <*> str
217
221
, pure PostIndex
218
222
] <* end
219
223
```
0 commit comments