on master help sign in
tests
d4860a7Denis Redozubov
schematic.cabal+3−1
@@ -114,6 +114,7 @@ test-suite spec
114 , hspec-core
114 , hspec-core
115 , hspec-discover
115 , hspec-discover
116 , hspec-smallcheck
116 , hspec-smallcheck
117+ , lens
117 , regex-compat
118 , regex-compat
118 , schematic
119 , schematic
119 , smallcheck
120 , smallcheck
@@ -124,4 +125,5 @@ test-suite spec
124 , unordered-containers
125 , unordered-containers
125 , validationt >= 0.1.0.1
126 , validationt >= 0.1.0.1
126 , vinyl
127 , vinyl
127− other-modules: SchemaSpec
128+ other-modules: SchemaSpec
129+ , LensSpec
src/Data/Schematic.hs+2
@@ -3,6 +3,7 @@
3
3
4module Data.Schematic
4module Data.Schematic
5 ( module Data.Schematic.Schema
5 ( module Data.Schematic.Schema
6+ , module Data.Schematic.Lens
6 , module Data.Schematic.Migration
7 , module Data.Schematic.Migration
7 , module Data.Schematic.Utils
8 , module Data.Schematic.Utils
8 , decodeAndValidateJson
9 , decodeAndValidateJson
@@ -25,6 +26,7 @@ import Data.Aeson as J
25import Data.Aeson.Types as J
26import Data.Aeson.Types as J
26import Data.ByteString.Lazy as BL
27import Data.ByteString.Lazy as BL
27import Data.Functor.Identity
28import Data.Functor.Identity
29+import Data.Schematic.Lens
28import Data.Schematic.Migration
30import Data.Schematic.Migration
29import Data.Schematic.Schema
31import Data.Schematic.Schema
30import Data.Schematic.Utils
32import Data.Schematic.Utils
src/Data/Schematic/Lens.hs+6−15
@@ -6,7 +6,6 @@
6module Data.Schematic.Lens where
6module Data.Schematic.Lens where
7
7
8import Data.Proxy
8import Data.Proxy
9−import Data.Schematic.Migration
10import Data.Schematic.Schema
9import Data.Schematic.Schema
11import Data.Vinyl
10import Data.Vinyl
12import Data.Vinyl.Functor
11import Data.Vinyl.Functor
@@ -44,32 +43,24 @@ class i ~ FIndex fn rs => FElem (fn :: Symbol) (rs :: [(Symbol, Schema)]) (i ::
44
43
45instance FElem fn ('(fn, r) ': rs) 'Z where
44instance FElem fn ('(fn, r) ': rs) 'Z where
46 type ByRevision fn ('(fn, r) ': rs) 'Z = r
45 type ByRevision fn ('(fn, r) ': rs) 'Z = r
46+
47 flens _ f (x :& xs) = fmap (:& xs) (f x)
47 flens _ f (x :& xs) = fmap (:& xs) (f x)
48 {-# INLINE flens #-}
48 {-# INLINE flens #-}
49+
49 fget k = getConst . flens k Const
50 fget k = getConst . flens k Const
50 {-# INLINE fget #-}
51 {-# INLINE fget #-}
52+
51 fput y = getIdentity . flens Proxy (\_ -> Identity y)
53 fput y = getIdentity . flens Proxy (\_ -> Identity y)
52 {-# INLINE fput #-}
54 {-# INLINE fput #-}
53
55
54instance (FIndex r (s ': rs) ~ 'S i, FElem r rs i) => FElem r (s ': rs) ('S i) where
56instance (FIndex r (s ': rs) ~ 'S i, FElem r rs i) => FElem r (s ': rs) ('S i) where
55 type ByRevision fn (s ': rs) ('S i) = ByRevision fn rs i
57 type ByRevision fn (s ': rs) ('S i) = ByRevision fn rs i
58+
56 flens p f (x :& xs) = fmap (x :&) (flens p f xs)
59 flens p f (x :& xs) = fmap (x :&) (flens p f xs)
57 {-# INLINE flens #-}
60 {-# INLINE flens #-}
61+
58 fget k = getConst . flens k Const
62 fget k = getConst . flens k Const
59 {-# INLINE fget #-}
63 {-# INLINE fget #-}
64+
60 fput y = getIdentity . flens Proxy (\_ -> Identity y)
65 fput y = getIdentity . flens Proxy (\_ -> Identity y)
61 {-# INLINE fput #-}
66 {-# 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
1+resolver: lts-9.01
2−#resolver: ghc-8.0.2
3
2
4# User packages to be built.
3# User packages to be built.
5# Various formats can be used as shown in the example below.
4# Various formats can be used as shown in the example below.