Skip to content

Commit 0c7051f

Browse files
authored
Replace Data.Validation.Semiring.unV by Data.Validation.Semiring.validation (#79)
* Replace Data.Validation.Semiring.unV by Data.Validation.Semiring.validation * Import Data.Generic.Rep from prelude
1 parent 9ff354d commit 0c7051f

File tree

4 files changed

+11
-13
lines changed

4 files changed

+11
-13
lines changed

bower.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
"devDependencies": {
4444
"purescript-console": "master",
4545
"purescript-assert": "master",
46-
"purescript-record": "master",
47-
"purescript-generics-rep": "master"
46+
"purescript-record": "master"
4847
}
4948
}

spago.dhall

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
, "effect"
88
, "either"
99
, "foldable-traversable"
10-
, "generics-rep"
1110
, "integers"
1211
, "js-uri"
1312
, "lists"

src/Routing/Match.purs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import Data.Semiring.Free (Free, free)
1616
import Data.String.NonEmpty (NonEmptyString)
1717
import Data.String.NonEmpty as NES
1818
import Data.Tuple (Tuple(..), snd)
19-
import Data.Validation.Semiring (V, invalid, unV)
19+
import Data.Validation.Semiring (V, invalid, validation)
2020
import Data.Number as Number
2121
import Routing.Match.Error (MatchError(..), showMatchError)
2222
import Routing.Types (Route, RoutePart(..))
@@ -27,7 +27,7 @@ derive instance newtypeMatch :: Newtype (Match a) _
2727

2828
instance matchFunctor :: Functor Match where
2929
map fn (Match r2e) = Match $ \r ->
30-
unV invalid (\(Tuple rs a) -> pure $ Tuple rs (fn a)) $ r2e r
30+
validation invalid (\(Tuple rs a) -> pure $ Tuple rs (fn a)) $ r2e r
3131

3232
instance matchAlt :: Alt Match where
3333
alt (Match r2e1) (Match r2e2) = Match $ \r -> do
@@ -40,11 +40,11 @@ instance matchAlternative :: Alternative Match
4040

4141
instance matchApply :: Apply Match where
4242
apply (Match r2a2b) (Match r2a) =
43-
Match $ (\r -> unV (processFnErr r) processFnRes (r2a2b r))
43+
Match $ (\r -> validation (processFnErr r) processFnRes (r2a2b r))
4444
where processFnErr r err =
45-
invalid $ err * unV identity (const one) (r2a r)
45+
invalid $ err * validation identity (const one) (r2a r)
4646
processFnRes (Tuple rs a2b) =
47-
unV invalid (\(Tuple rss a) -> pure $ Tuple rss (a2b a)) (r2a rs)
47+
validation invalid (\(Tuple rss a) -> pure $ Tuple rss (a2b a)) (r2a rs)
4848

4949
instance matchApplicative :: Applicative Match where
5050
pure a = Match \r -> pure $ Tuple r a
@@ -160,7 +160,7 @@ list (Match r2a) =
160160
Match $ go Nil
161161
where go :: List a -> Route -> V (Free MatchError) (Tuple Route (List a))
162162
go accum r =
163-
unV
163+
validation
164164
(const $ pure (Tuple r (reverse accum)))
165165
(\(Tuple rs a) -> go (Cons a accum) rs)
166166
(r2a r)
@@ -169,7 +169,7 @@ list (Match r2a) =
169169
-- [[String]] -fold with semicolon-> [String] -fold with newline-> String
170170
runMatch :: forall a. Match a -> Route -> Either String a
171171
runMatch (Match fn) route =
172-
unV foldErrors (Right <<< snd) $ fn route
172+
validation foldErrors (Right <<< snd) $ fn route
173173
where
174174
foldErrors errs =
175175
Left $ foldl (\b a -> a <> "\n" <> b) "" do
@@ -195,7 +195,7 @@ runMatch (Match fn) route =
195195
-- | ```
196196
eitherMatch :: forall a b. Match (Either a b) -> Match b
197197
eitherMatch (Match r2eab) = Match $ \r ->
198-
unV invalid runEither $ (r2eab r)
198+
validation invalid runEither $ (r2eab r)
199199
where
200200
runEither (Tuple rs eit) =
201201
case eit of
@@ -209,4 +209,4 @@ eitherMatch (Match r2eab) = Match $ \r ->
209209
-- | -- (Right (fromFoldable [(Tuple "a" "1")]))
210210
-- | ```
211211
optionalMatch :: forall a. Match a -> Match (Maybe a)
212-
optionalMatch (Match fn) = Match (\route -> unV (const $ pure (Tuple route Nothing)) (pure <<< map Just) $ fn route)
212+
optionalMatch (Match fn) = Match (\route -> validation (const $ pure (Tuple route Nothing)) (pure <<< map Just) $ fn route)

test/Test/Main.purs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import Data.Bifunctor (lmap)
77
import Data.Either (Either(..))
88
import Data.Foldable (oneOf)
99
import Data.Generic.Rep (class Generic)
10-
import Data.Generic.Rep.Show (genericShow)
1110
import Data.List (List)
1211
import Data.List as L
1312
import Data.Map as M
13+
import Data.Show.Generic (genericShow)
1414
import Data.String.NonEmpty (NonEmptyString)
1515
import Data.String.NonEmpty as NES
1616
import Data.Tuple (Tuple(..))

0 commit comments

Comments
 (0)