11module Routing.Match where
22
3- import Prelude
3+
4+ import Prelude (class Applicative , class Apply , class Functor , pure , bind , const , one , id , unit , ($), (<<<), (<$>), (<>), (*), (==))
45import Data.Either (Either (..))
56import Data.Tuple (Tuple (..), snd )
67import Data.Maybe (Maybe (..))
78import Data.List (List (..), reverse )
8- import Control.Alt (Alt , (<|>))
9- import Control.Plus (Plus )
10- import Control.Alternative (Alternative )
9+ import Control.Alt (class Alt , (<|>))
10+ import Control.Plus (class Plus )
11+ import Control.Alternative (class Alternative )
1112import Global (readFloat , isNaN )
1213import Data.Semiring.Free (Free (), free , runFree )
13- import Data.Foldable
14- import Data.Validation.Semiring
14+ import Data.Foldable ( foldl )
15+ import Data.Validation.Semiring ( V , invalid , unV )
1516
1617
17- import qualified Data.Map as M
18+ import Data.Map as M
1819
19- import Routing.Types
20- import Routing.Match.Class
21- import Routing.Match.Error
20+ import Routing.Types ( Route , RoutePart (..))
21+ import Routing.Match.Class ( class MatchClass )
22+ import Routing.Match.Error ( MatchError (..), showMatchError )
2223
2324newtype Match a = Match (Route -> V (Free MatchError ) (Tuple Route a ))
2425unMatch :: forall a . Match a -> (Route -> V (Free MatchError ) (Tuple Route a ))
@@ -84,7 +85,7 @@ instance matchMatchClass :: MatchClass Match where
8485
8586instance matchFunctor :: Functor Match where
8687 map fn (Match r2e) = Match $ \r ->
87- runV invalid (\(Tuple rs a) -> pure $ Tuple rs (fn a)) $ r2e r
88+ unV invalid (\(Tuple rs a) -> pure $ Tuple rs (fn a)) $ r2e r
8889
8990instance matchAlt :: Alt Match where
9091 alt (Match r2e1) (Match r2e2) = Match $ \r -> do
@@ -97,11 +98,11 @@ instance matchAlternative :: Alternative Match
9798
9899instance matchApply :: Apply Match where
99100 apply (Match r2a2b) (Match r2a) =
100- Match $ (\r -> runV (processFnErr r) processFnRes (r2a2b r))
101+ Match $ (\r -> unV (processFnErr r) processFnRes (r2a2b r))
101102 where processFnErr r err =
102- invalid $ err * runV id (const one) (r2a r)
103+ invalid $ err * unV id (const one) (r2a r)
103104 processFnRes (Tuple rs a2b) =
104- runV invalid (\(Tuple rss a) -> pure $ Tuple rss (a2b a)) (r2a rs)
105+ unV invalid (\(Tuple rss a) -> pure $ Tuple rss (a2b a)) (r2a rs)
105106
106107instance matchApplicative :: Applicative Match where
107108 pure a = Match \r -> pure $ Tuple r a
@@ -113,7 +114,7 @@ list (Match r2a) =
113114 Match $ go Nil
114115 where go :: List a -> Route -> V (Free MatchError ) (Tuple Route (List a ))
115116 go accum r =
116- runV
117+ unV
117118 (const $ pure (Tuple r (reverse accum)))
118119 (\(Tuple rs a) -> go (Cons a accum) rs)
119120 (r2a r)
@@ -125,7 +126,7 @@ list (Match r2a) =
125126-- [[String]] -fold with semicolon-> [String] -fold with newline-> String
126127runMatch :: forall a . Match a -> Route -> Either String a
127128runMatch (Match fn) route =
128- runV foldErrors (Right <<< snd) $ fn route
129+ unV foldErrors (Right <<< snd) $ fn route
129130 where
130131 foldErrors errs =
131132 Left $ foldl (\b a -> a <> " \n " <> b) " " do
@@ -151,7 +152,7 @@ runMatch (Match fn) route =
151152-- | ```
152153eitherMatch :: forall a b . Match (Either a b ) -> Match b
153154eitherMatch (Match r2eab) = Match $ \r ->
154- runV invalid runEither $ (r2eab r)
155+ unV invalid runEither $ (r2eab r)
155156 where
156157 runEither (Tuple rs eit) =
157158 case eit of
0 commit comments