git.iko.soy/typeable/schematic
on master help sign in
tests
commitd4860a741a6687fb046c318b29f4ff950c52064c authorDenis Redozubov <denis.redozubov@gmail.com> dateTue 22 Aug 2017, 17:00 (9 years ago) parent585f72b
4 files changed+12−18
schematic.cabal+3−1 src/Data/Schematic.hs+2 src/Data/Schematic/Lens.hs+6−15 stack.yaml+1−2
schematic.cabal+3−1
@@ -114,6 +114,7 @@ test-suite spec
114114 , hspec-core
115115 , hspec-discover
116116 , hspec-smallcheck
117+ , lens
117118 , regex-compat
118119 , schematic
119120 , smallcheck
@@ -124,4 +125,5 @@ test-suite spec
124125 , unordered-containers
125126 , validationt >= 0.1.0.1
126127 , vinyl
127− other-modules: SchemaSpec
128+ other-modules: SchemaSpec
129+ , LensSpec
src/Data/Schematic.hs+2
@@ -3,6 +3,7 @@
33
44module Data.Schematic
55 ( module Data.Schematic.Schema
6+ , module Data.Schematic.Lens
67 , module Data.Schematic.Migration
78 , module Data.Schematic.Utils
89 , decodeAndValidateJson
@@ -25,6 +26,7 @@ import Data.Aeson as J
2526import Data.Aeson.Types as J
2627import Data.ByteString.Lazy as BL
2728import Data.Functor.Identity
29+import Data.Schematic.Lens
2830import Data.Schematic.Migration
2931import Data.Schematic.Schema
3032import Data.Schematic.Utils
src/Data/Schematic/Lens.hs+6−15
@@ -6,7 +6,6 @@
66module Data.Schematic.Lens where
77
88import Data.Proxy
9−import Data.Schematic.Migration
109import Data.Schematic.Schema
1110import Data.Vinyl
1211import Data.Vinyl.Functor
@@ -44,32 +43,24 @@ class i ~ FIndex fn rs => FElem (fn :: Symbol) (rs :: [(Symbol, Schema)]) (i ::
4443
4544instance FElem fn ('(fn, r) ': rs) 'Z where
4645 type ByRevision fn ('(fn, r) ': rs) 'Z = r
46+
4747 flens _ f (x :& xs) = fmap (:& xs) (f x)
4848 {-# INLINE flens #-}
49+
4950 fget k = getConst . flens k Const
5051 {-# INLINE fget #-}
52+
5153 fput y = getIdentity . flens Proxy (\_ -> Identity y)
5254 {-# INLINE fput #-}
5355
5456instance (FIndex r (s ': rs) ~ 'S i, FElem r rs i) => FElem r (s ': rs) ('S i) where
5557 type ByRevision fn (s ': rs) ('S i) = ByRevision fn rs i
58+
5659 flens p f (x :& xs) = fmap (x :&) (flens p f xs)
5760 {-# INLINE flens #-}
61+
5862 fget k = getConst . flens k Const
5963 {-# INLINE fget #-}
64+
6065 fput y = getIdentity . flens Proxy (\_ -> Identity y)
6166 {-# INLINE fput #-}
62−
63−type SchemaExample
64− = 'SchemaObject
65− '[ '("foo", 'SchemaArray '[ 'AEq 1] ('SchemaNumber '[ 'NGt 10]))
66− , '("bar", 'SchemaOptional ('SchemaText '[ 'TEnum '["foo", "bar"]]))]
67−
68−type TestMigration =
69− 'Migration "test_revision"
70− '[ 'Diff '[ 'PKey "bar" ] ('Update ('SchemaText '[]))
71− , 'Diff '[ 'PKey "foo" ] ('Update ('SchemaNumber '[])) ]
72−
73−type VS = 'Versioned SchemaExample '[ TestMigration ]
74−
75−type Ex = FIndex "initial" (AllVersions VS)
stack.yaml+1−2
@@ -1,5 +1,4 @@
1−resolver: lts-8.12
2−#resolver: ghc-8.0.2
1+resolver: lts-9.01
32
43# User packages to be built.
54# Various formats can be used as shown in the example below.