composite-aeson-refined 0.4.1.0 → 0.4.2.0
raw patch · 2 files changed
+8/−3 lines, 2 filesdep +aeson-better-errorsdep +mtlPVP ok
version bump matches the API change (PVP)
Dependencies added: aeson-better-errors, mtl
API changes (from Hackage documentation)
Files
composite-aeson-refined.cabal view
@@ -3,7 +3,7 @@ -- see: https://github.com/sol/hpack name: composite-aeson-refined-version: 0.4.1.0+version: 0.4.2.0 synopsis: composite-aeson support for Refined from the refined package description: JsonFormat and DefaultJsonFormat for Refined category: Records@@ -21,8 +21,10 @@ default-extensions: DataKinds FlexibleContexts FlexibleInstances GeneralizedNewtypeDeriving LambdaCase MultiParamTypeClasses MultiWayIf OverloadedStrings PatternSynonyms PolyKinds QuasiQuotes RankNTypes ScopedTypeVariables StandaloneDeriving StrictData TemplateHaskell TupleSections TypeFamilies TypeOperators ViewPatterns ghc-options: -Wall -O2 build-depends:- base >= 4.7 && < 5+ aeson-better-errors+ , base >= 4.7 && < 5 , composite-aeson+ , mtl , refined exposed-modules: Composite.Aeson.Refined
src/Composite/Aeson/Refined.hs view
@@ -2,6 +2,8 @@ module Composite.Aeson.Refined (refinedJsonFormat) where import Composite.Aeson (DefaultJsonFormat, defaultJsonFormat, JsonFormat(JsonFormat), JsonProfunctor(JsonProfunctor))+import Control.Monad.Error.Class (throwError)+import qualified Data.Aeson.BetterErrors as ABE import Refined (Predicate, Refined, refine, unrefine) -- |Given a @'JsonFormat' e a@, produce a @JsonFormat e ('Refined' p a)@ where @p@ is some 'Predicate' from the refined library for @a@.@@ -12,7 +14,8 @@ refinedJsonFormat (JsonFormat (JsonProfunctor oa ia)) = JsonFormat $ JsonProfunctor o i where o = oa . unrefine- i = either fail pure . refine =<< ia+ i = either toss pure . refine =<< ia+ toss = throwError . ABE.BadSchema [] . ABE.FromAeson instance (DefaultJsonFormat a, Predicate p a) => DefaultJsonFormat (Refined p a) where defaultJsonFormat = refinedJsonFormat defaultJsonFormat