@@ -41,10 +41,12 @@ instance matchAlternative :: Alternative Match
41
41
instance matchApply :: Apply Match where
42
42
apply (Match r2a2b) (Match r2a) =
43
43
Match $ (\r -> validation (processFnErr r) processFnRes (r2a2b r))
44
- where processFnErr r err =
45
- invalid $ err * validation identity (const one) (r2a r)
46
- processFnRes (Tuple rs a2b) =
47
- validation invalid (\(Tuple rss a) -> pure $ Tuple rss (a2b a)) (r2a rs)
44
+ where
45
+ processFnErr r err =
46
+ invalid $ err * validation identity (const one) (r2a r)
47
+
48
+ processFnRes (Tuple rs a2b) =
49
+ validation invalid (\(Tuple rss a) -> pure $ Tuple rss (a2b a)) (r2a rs)
48
50
49
51
instance matchApplicative :: Applicative Match where
50
52
pure a = Match \r -> pure $ Tuple r a
@@ -61,7 +63,7 @@ lit input = Match \route ->
61
63
Cons (Path i) rs | i == input ->
62
64
pure $ Tuple rs unit
63
65
Cons (Path _) _ ->
64
- invalid $ free $ UnexpectedPath input
66
+ invalid $ free $ UnexpectedPath input
65
67
_ ->
66
68
invalid $ free ExpectedPathPart
67
69
@@ -119,9 +121,8 @@ param key = Match \route ->
119
121
Just el -> do
120
122
let remainingParams = M .delete key map
121
123
pure $
122
- if M .isEmpty remainingParams
123
- then Tuple rs el
124
- else Tuple (Cons (Query remainingParams) rs) el
124
+ if M .isEmpty remainingParams then Tuple rs el
125
+ else Tuple (Cons (Query remainingParams) rs) el
125
126
_ ->
126
127
invalid $ free ExpectedQuery
127
128
@@ -158,12 +159,13 @@ nonempty =
158
159
list :: forall a . Match a -> Match (List a )
159
160
list (Match r2a) =
160
161
Match $ go Nil
161
- where go :: List a -> Route -> V (Free MatchError ) (Tuple Route (List a ))
162
- go accum r =
163
- validation
164
- (const $ pure (Tuple r (reverse accum)))
165
- (\(Tuple rs a) -> go (Cons a accum) rs)
166
- (r2a r)
162
+ where
163
+ go :: List a -> Route -> V (Free MatchError ) (Tuple Route (List a ))
164
+ go accum r =
165
+ validation
166
+ (const $ pure (Tuple r (reverse accum)))
167
+ (\(Tuple rs a) -> go (Cons a accum) rs)
168
+ (r2a r)
167
169
168
170
-- It groups `Free MatchError` -> [[MatchError]] -map with showMatchError ->
169
171
-- [[String]] -fold with semicolon-> [String] -fold with newline-> String
@@ -174,8 +176,7 @@ runMatch (Match fn) route =
174
176
foldErrors errs =
175
177
Left $ foldl (\b a -> a <> " \n " <> b) " " do
176
178
es <- reverse <$> unwrap errs
177
- pure $ foldl (\b a -> a <> " ;" <> b) " " $ showMatchError <$> es
178
-
179
+ pure $ foldl (\b a -> a <> " ;" <> b) " " $ showMatchError <$> es
179
180
180
181
-- | if we match something that can fail then we have to
181
182
-- | match `Either a b`. This function converts matching on such
0 commit comments