Skip to content

Commit

Permalink
Update to fix fourmolu
Browse files Browse the repository at this point in the history
  • Loading branch information
onslaughtq committed Jul 19, 2023
1 parent e784b8c commit 5721b75
Show file tree
Hide file tree
Showing 10 changed files with 368 additions and 352 deletions.
2 changes: 1 addition & 1 deletion compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
services:
dev:
image: ghcr.io/flipstone/haskell-tools:debian-unstable-ghc-9.4.5-2023-07-17-f86296e
image: ghcr.io/flipstone/haskell-tools:debian-unstable-ghc-9.4.5-2023-07-18-1d8bf61
environment:
STACK_ROOT: /stack-root
IN_DEV_CONTAINER: 'true'
Expand Down
14 changes: 14 additions & 0 deletions fourmolu.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
indentation: 2
function-arrows: trailing
comma-style: leading # default
import-export-style: leading
indent-wheres: false # default
record-brace-space: true
newlines-between-decls: 1 # default
haddock-style: multi-line # default
haddock-style-module: # default
let-style: newline
in-style: left-align
unicode: never # default
respectful: true # default
single-constraint-parens: never
12 changes: 6 additions & 6 deletions src/Data/Validation.hs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module Data.Validation (
module Data.Validation.Aeson,
module Data.Validation.Primitives,
module Data.Validation.Types,
module Data.Validation.XML,
) where
module Data.Validation
( module Data.Validation.Aeson
, module Data.Validation.Primitives
, module Data.Validation.Types
, module Data.Validation.XML
) where

import Data.Validation.Aeson
import Data.Validation.Primitives
Expand Down
88 changes: 44 additions & 44 deletions src/Data/Validation/Aeson.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,65 +16,65 @@ import Data.Validation.Types

decodeValidJSON :: Validator Value a -> LazyBS.ByteString -> ValidationResult a
decodeValidJSON validator input =
runIdentity (decodeValidJSONT (liftV validator) input)
runIdentity (decodeValidJSONT (liftV validator) input)

decodeValidJSONStrict :: Validator Value a -> BS.ByteString -> ValidationResult a
decodeValidJSONStrict validator input =
runIdentity (decodeValidJSONStrictT (liftV validator) input)
runIdentity (decodeValidJSONStrictT (liftV validator) input)

decodeValidJSONT ::
(Applicative m) =>
ValidatorT Value m a ->
LazyBS.ByteString ->
m (ValidationResult a)
Applicative m =>
ValidatorT Value m a ->
LazyBS.ByteString ->
m (ValidationResult a)
decodeValidJSONT validator input =
case eitherDecode input of
Left err -> pure $ Invalid (errMessage $ Text.pack err)
Right value -> runValidatorT validator (value :: Value)
case eitherDecode input of
Left err -> pure $ Invalid (errMessage $ Text.pack err)
Right value -> runValidatorT validator (value :: Value)

decodeValidJSONStrictT ::
(Applicative m) =>
ValidatorT Value m a ->
BS.ByteString ->
m (ValidationResult a)
Applicative m =>
ValidatorT Value m a ->
BS.ByteString ->
m (ValidationResult a)
decodeValidJSONStrictT validator input =
case eitherDecodeStrict input of
Left err -> pure $ Invalid (errMessage $ Text.pack err)
Right value -> runValidatorT validator (value :: Value)
case eitherDecodeStrict input of
Left err -> pure $ Invalid (errMessage $ Text.pack err)
Right value -> runValidatorT validator (value :: Value)

instance Validatable Value where
inputText (String text) = Just text
inputText _ = Nothing
inputText (String text) = Just text
inputText _ = Nothing

inputNull Null = IsNull
inputNull _ = NotNull
inputNull Null = IsNull
inputNull _ = NotNull

inputBool (Bool True) = Just True
inputBool (Bool False) = Just False
inputBool _ = Nothing
inputBool (Bool True) = Just True
inputBool (Bool False) = Just False
inputBool _ = Nothing

arrayItems (Array items) = Just items
arrayItems _ = Nothing
arrayItems (Array items) = Just items
arrayItems _ = Nothing

scientificNumber (Number sci) = Just sci
scientificNumber _ = Nothing
scientificNumber (Number sci) = Just sci
scientificNumber _ = Nothing

lookupChild attrName (Object hmap) =
LookupResult $
KeyMap.lookup (Key.fromText attrName) hmap
lookupChild _ _ = InvalidLookup
lookupChild attrName (Object hmap) =
LookupResult $
KeyMap.lookup (Key.fromText attrName) hmap
lookupChild _ _ = InvalidLookup

instance ToJSON Errors where
toJSON (Messages set) =
Array
. Vec.fromList
. map toJSON
. Set.toList
$ set
toJSON (Group attrs) =
Object
. KeyMap.fromList
. Map.toList
. Map.mapKeys Key.fromText
. Map.map toJSON
$ attrs
toJSON (Messages set) =
Array
. Vec.fromList
. map toJSON
. Set.toList
$ set
toJSON (Group attrs) =
Object
. KeyMap.fromList
. Map.toList
. Map.mapKeys Key.fromText
. Map.map toJSON
$ attrs
Loading

0 comments on commit 5721b75

Please sign in to comment.