packages feed

bookkeeper 0.2.3 → 0.2.4

raw patch · 5 files changed

+141/−3 lines, 5 files

Files

CHANGELOG.md view
@@ -1,3 +1,7 @@+# 0.2.4++* Added 'rlens' and lens 'IsLabel' instance.+ # 0.2.3  * Implement 'fromRecord' for converting values from record.
bookkeeper.cabal view
@@ -1,9 +1,9 @@--- This file has been generated from package.yaml by hpack version 0.14.0.+-- This file has been generated from package.yaml by hpack version 0.14.1. -- -- see: https://github.com/sol/hpack  name:           bookkeeper-version:        0.2.3+version:        0.2.4 synopsis:       Anonymous records and overloaded labels description:    Please see README.md category:       Data Structures, Records@@ -20,6 +20,7 @@  extra-source-files:     CHANGELOG.md+    package.yaml     README.md  source-repository head@@ -39,6 +40,7 @@       Bookkeeper       Bookkeeper.Internal       Bookkeeper.Internal.Errors+      Bookkeeper.Lens   default-language: Haskell2010  executable readme
+ package.yaml view
@@ -0,0 +1,93 @@+name:                bookkeeper+version:             0.2.4+synopsis:            Anonymous records and overloaded labels+description:         Please see README.md+homepage:            http://github.com/turingjump/bookkeeper#readme+license:             BSD3+license-file:        LICENSE+author:              Julian K. Arni+maintainer:          jkarni@gmail.com+copyright:           (c) Julian K. Arni+github:              turingjump/bookkeeper+tested-with:         GHC == 8.0.1+category:            Data Structures, Records+extra-source-files:+  - CHANGELOG.md+  - README.md+  - package.yaml++ghc-options: -Wall++dependencies:+  - base >= 4.9 && < 4.10+  - type-level-sets+  - data-default-class+++library:+  source-dirs:      src+  other-modules:    []+  default-extensions: &allExts+    - AutoDeriveTypeable+    - ConstraintKinds+    - DataKinds+    - DefaultSignatures+    - DeriveFunctor+    - DeriveGeneric+    - DeriveFoldable+    - DeriveTraversable+    - FlexibleContexts+    - FlexibleInstances+    - FunctionalDependencies+    - GADTs+    - MultiParamTypeClasses+    - KindSignatures+    - TypeInType+    - OverloadedStrings+    - RankNTypes+    - ScopedTypeVariables+    - TypeApplications+    - TypeFamilies+    - TypeOperators+    - OverloadedLabels+    - MagicHash++tests:+  spec:+    main:            Spec.hs+    source-dirs:     test+    default-extensions: *allExts+    dependencies:+      - bookkeeper+      - hspec > 2 && < 3+      - QuickCheck >= 2.8 && < 2.9+  doctest:+    main:            Doctest.hs+    source-dirs:     test+    default-extensions: *allExts+    dependencies:+      - doctest >= 0.9 && < 0.12+      - Glob >= 0.7 && < 0.8+      - yaml == 0.8.*++benchmarks:+  bench:+    main:            Main.hs+    source-dirs:     bench+    default-extensions: *allExts+    dependencies:+      - bookkeeper+      - criterion+    ghc-options:     -O2+++executables:+  readme:+    main:                Readme.lhs+    ghc-options:         -pgmL markdown-unlit -fno-warn-unused-top-binds+    source-dirs:         exec+    default-extensions:  []+    other-modules:       []+    dependencies:        base >=4.9 && < 4.10+                       , bookkeeper+                       , markdown-unlit
src/Bookkeeper/Internal.hs view
@@ -207,7 +207,6 @@         ) => Key field -> Book' old -> Book (old Map.:\ field) delete _ (Book bk) = Book $ Map.submap bk - -- * Generics  class FromGeneric a book | a -> book where
+ src/Bookkeeper/Lens.hs view
@@ -0,0 +1,40 @@+{-# LANGUAGE UndecidableInstances #-}+{-# OPTIONS_GHC -fno-warn-orphans #-}+module Bookkeeper.Lens where++import GHC.OverloadedLabels+import Bookkeeper.Internal+import GHC.TypeLits (Symbol, KnownSymbol, TypeError, ErrorMessage(..))++-- * Lenses++-- | Build a lens from a field+--+-- @+-- julian ^. rlens #age+--    = 28+-- @+-- Symbols can also be used directly as lenses, so you probably don't need to use 'rlens':+--+-- @+-- julian ^. #age+--    = 28+-- @+--+-- @+-- julian & #age .~ 29+--    = Book {age = 29, name = "Julian K. Arni"}+-- @+rlens :: (Settable field val' old new, Gettable field old val, Functor f) =>+          Key field -> (val -> f val') -> (Book' old -> f (Book' new))+rlens f = lens (\r -> get f r) (\r v -> set f v r)+  where lens sa sbt afb s = sbt s <$> afb (sa s)++instance (Settable field valnew old new,+          Gettable field old val,+          Functor f,+          s2ft ~ (Book' old -> f (Book' new)))+         => IsLabel (field :: Symbol)+                    ((val -> f valnew) -> s2ft) where+  fromLabel _ = rlens (Key @field)+