hasbolt 0.1.3.2 → 0.1.3.3
raw patch · 2 files changed
+64/−6 lines, 2 filesdep +contravariantdep ~basedep ~connectiondep ~containersPVP: minor bump suggested
API additions: PVP suggests at least a minor version bump
Dependencies added: contravariant
Dependency ranges changed: base, connection, containers, network
API changes (from Hackage documentation)
+ Database.Bolt.Lens: exact :: RecordValue a => Fold Value a
+ Database.Bolt.Lens: field :: RecordValue a => Text -> Fold Record a
+ Database.Bolt.Lens: prop :: RecordValue a => Text -> Fold Node a
Files
- hasbolt.cabal +11/−6
- src/Database/Bolt/Lens.hs +53/−0
hasbolt.cabal view
@@ -1,6 +1,6 @@ cabal-version: >=1.10 name: hasbolt-version: 0.1.3.2+version: 0.1.3.3 license: BSD3 license-file: LICENSE copyright: (c) 2018 Pavel Yakovlev@@ -35,6 +35,7 @@ exposed-modules: Database.Bolt Database.Bolt.Lazy+ Database.Bolt.Lens hs-source-dirs: src other-modules: Database.Bolt.Value.Type@@ -57,9 +58,13 @@ binary >=0.8.3.0 && <1.0, data-binary-ieee754 >=0.4.4 && <0.5, transformers >=0.5.2.0 && <0.6,- network >=2.6.3.1 && <2.9,- connection >=0.2.8 && <0.3,+ network >=2.6.3.1 && <3.1,+ connection >=0.2.8 && <0.4, data-default >=0.7.1.1 && <0.8+ + if impl(ghc <8.6)+ build-depends:+ contravariant >=1.4.1 && <1.6 test-suite hasbolt-test type: exitcode-stdio-1.0@@ -70,9 +75,9 @@ build-depends: base >=4.8 && <5, hasbolt -any,- hspec >=2.4.1 && <2.7,- QuickCheck >=2.9 && <2.13,+ hspec >=2.4.1 && <2.8,+ QuickCheck >=2.9 && <2.14, hex >=0.1.2 && <0.2, text >=1.2.3.1 && <1.3,- containers >=0.5.11.0 && <0.6,+ containers >=0.6.0.1 && <0.7, bytestring >=0.10.8.2 && <0.11
+ src/Database/Bolt/Lens.hs view
@@ -0,0 +1,53 @@+{-# LANGUAGE RankNTypes #-}++module Database.Bolt.Lens+ ( exact+ , field+ , prop+ )+where++import Data.Functor.Contravariant (Contravariant (..))+import Data.Map.Strict (Map)+import qualified Data.Map.Strict as M+import Data.Text (Text)+import qualified Database.Bolt as B++-- | @Getter@ from @lens@ package.+type Getter s a = forall f. (Functor f, Contravariant f) => (a -> f a) -> (s -> f s)++-- | @Fold@ from @lens@ package.+type Fold s a = forall f. (Applicative f, Contravariant f) => (a -> f a) -> (s -> f s)++-- | This 'Fold' extracts value of required type from 'B.Value'. If 'B.Value' contains wrong+-- type, 'exact' is an empty 'Fold'.+exact :: B.RecordValue a => Fold B.Value a+exact = to B.exact . _Just++-- | Extract field by given key from 'B.Record'. If there is no such key or the type is wrong,+-- this is an empty 'Fold'.+field :: B.RecordValue a => Text -> Fold B.Record a+field key = ix key . exact++-- | Extract any property from 'B.Node'. If there is no such property or the type is wrong,+-- this is an emtpy 'Fold'.+prop :: B.RecordValue a => Text -> Fold B.Node a+prop key = to B.nodeProps . ix key . exact++-- INTERNAL STUFF++-- | Simplistic implementation of @to@ from @lens@.+to :: (s -> a) -> Getter s a+to f g = contramap f . g . f++-- | Simplistic implementation of @_Just@ prism. We use this prism only in one direction,+-- so @Fold@ suffices.+_Just :: Fold (Maybe a) a+_Just f s =+ case s of+ Just a -> s <$ f a+ Nothing -> pure s++-- | Simplistic implementation of @ix@. We don't need a full lens here, so this is just a 'Fold'.+ix :: Ord k => k -> Fold (Map k v) v+ix k = to (M.lookup k) . _Just