packages feed

mini 1.0.1.0 → 1.1.0.0

raw patch · 4 files changed

+67/−102 lines, 4 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

- Mini.Lens: lens :: (s -> a) -> (s -> b -> t) -> Lens s t a b
- Mini.Lens: over :: Lens s t a b -> (a -> b) -> s -> t
- Mini.Lens: set :: Lens s t a b -> b -> s -> t
- Mini.Lens: type Lens s t a b = forall f. (Functor f) => (a -> f b) -> (s -> f t)
- Mini.Lens: view :: Lens s t a b -> s -> a
+ Mini.Optics.Lens: lens :: (s -> a) -> (s -> b -> t) -> Lens s t a b
+ Mini.Optics.Lens: over :: Lens s t a b -> (a -> b) -> s -> t
+ Mini.Optics.Lens: set :: Lens s t a b -> b -> s -> t
+ Mini.Optics.Lens: type Lens s t a b = forall f. (Functor f) => (a -> f b) -> (s -> f t)
+ Mini.Optics.Lens: view :: Lens s t a b -> s -> a

Files

CHANGELOG.md view
@@ -1,3 +1,9 @@+1.1.0.0 [2024-03-11]+--------------------+* Conventionalise module naming: package.section.title+    * Mini.Lens -> Mini.Optics.Lens+* Streamline optics documentation+ 1.0.1.0 [2024-03-10] -------------------- * Export transformers newtype constructors
− Mini/Lens.hs
@@ -1,100 +0,0 @@-{-# LANGUAGE RankNTypes #-}--{- | Minimal library of /van Laarhoven/ lenses: composable polymorphic record-updates--}-module Mini.Lens (-  -- * Types-  Lens,--  -- * Construction-  lens,--  -- * Reading-  view,--  -- * Modifying-  over,--  -- * Writing-  set,-) where--import Control.Applicative (-  Const (-    Const,-    getConst-  ),- )-import Data.Functor.Identity (-  Identity (-    Identity,-    runIdentity-  ),- )--{-- - Types- -}--{- | A purely functional reference for updating structures of type /s/ with-fields of type /a/ to structures of type /t/ with fields of type /b/--}-type Lens s t a b = forall f. (Functor f) => (a -> f b) -> (s -> f t)--{-- - Construction- -}--{- | From a getter and a setter to a lens--> data Foo = Foo { _bar :: Bar } deriving Show-> data Bar = Bar { _baz :: Int } deriving Show->-> bar :: Lens Foo Foo Bar Bar-> bar = lens _bar $ \s b -> s { _bar = b }->-> baz :: Lens Bar Bar Int Int-> baz = lens _baz $ \s b -> s { _baz = b }--}-lens :: (s -> a) -> (s -> b -> t) -> Lens s t a b-lens sa sbt ab s = sbt s <$> ab (sa s)--{-- - Reading- -}--{- | From a lens and a structure to the value of the field of the structure-referenced by the lens--> ghci> view (bar . baz) $ Foo (Bar 73)-> 73--}-view :: Lens s t a b -> s -> a-view o = getConst . o Const--{-- - Modifying- -}--{- | From a lens, an operation and a structure to the structure updated by-applying the operation to the value of the field referenced by the lens--> ghci> over (bar . baz) (+ 1) $ Foo (Bar 73)-> Foo {_bar = Bar {_baz = 74}}--}-over :: Lens s t a b -> (a -> b) -> s -> t-over o ab = runIdentity . o (Identity . ab)--{-- - Writing- -}--{- | From a lens, a value and a structure to the structure updated by setting-the field referenced by the lens to the value--> ghci> set (bar . baz) 21 $ Foo (Bar 73)-> Foo {_bar = Bar {_baz = 21}}--}-set :: Lens s t a b -> b -> s -> t-set o b = runIdentity . o (const $ Identity b)
+ Mini/Optics/Lens.hs view
@@ -0,0 +1,59 @@+{-# LANGUAGE RankNTypes #-}++-- | Compose polymorphic record updates with /van Laarhoven/ lenses+module Mini.Optics.Lens (+  -- * Type+  Lens,++  -- * Construction+  lens,++  -- * Operations+  view,+  over,+  set,+) where++import Control.Applicative (+  Const (+    Const,+    getConst+  ),+ )+import Data.Functor.Identity (+  Identity (+    Identity,+    runIdentity+  ),+ )++{-+ - Type+ -}++-- | A reference updating structures from /s/ to /t/ and fields from /a/ to /b/+type Lens s t a b = forall f. (Functor f) => (a -> f b) -> (s -> f t)++{-+ - Construction+ -}++-- | Make a lens from a getter and a setter+lens :: (s -> a) -> (s -> b -> t) -> Lens s t a b+lens sa sbt ab s = sbt s <$> ab (sa s)++{-+ - Operations+ -}++-- | Fetch the field referenced by a lens from a structure+view :: Lens s t a b -> s -> a+view o = getConst . o Const++-- | Update the field referenced by a lens with an operation on a structure+over :: Lens s t a b -> (a -> b) -> s -> t+over o ab = runIdentity . o (Identity . ab)++-- | Overwrite the field referenced by a lens with a value on a structure+set :: Lens s t a b -> b -> s -> t+set o b = runIdentity . o (const $ Identity b)
mini.cabal view
@@ -1,6 +1,6 @@ cabal-version:      2.4 name:               mini-version:            1.0.1.0+version:            1.1.0.0 license:            MIT license-file:       LICENSE copyright:          (c) 2023-2024 Victor Wallsten@@ -26,7 +26,7 @@   exposed-modules:     Mini.Data.Map     Mini.Data.Set-    Mini.Lens+    Mini.Optics.Lens     Mini.Transformers.Class     Mini.Transformers.EitherT     Mini.Transformers.ReaderT