changeset-lens 0.1.1 → 0.2
raw patch · 2 files changed
+27/−4 lines, 2 filesdep ~basedep ~changesetPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: base, changeset
API changes (from Hackage documentation)
+ Control.Monad.Changeset.Lens: changed :: RightAction w s => w -> Fold s s
+ Control.Monad.Changeset.Lens: changing :: RightAction w a => Setter' s a -> s -> w -> s
+ Control.Monad.Changeset.Lens: relativeTo :: RightTorsor w s => s -> Iso' s w
Files
changeset-lens.cabal view
@@ -1,6 +1,6 @@ cabal-version: 2.4 name: changeset-lens-version: 0.1.1+version: 0.2 synopsis: Stateful monad transformer based on monoidal actions description: A general state monad transformer with separate types for the state and the possible changes.@@ -64,8 +64,8 @@ Control.Monad.Changeset.Lens.Setter build-depends:- base >=4.12 && <4.22,- changeset ==0.1.1,+ base >=4.16 && <4.23,+ changeset ==0.2, containers >=0.6 && <0.8, indexed-traversable ^>=0.1.1, lens >=4.19.2 && <5.4,
src/Control/Monad/Changeset/Lens.hs view
@@ -11,8 +11,11 @@ import Prelude hiding (Foldable (..)) -- lens-import Control.Lens (Lens', Prism', Traversal')+import Control.Lens (Fold, Iso', Lens', Prism', Setter', Traversal', iso, over, to) +-- changeset+import Data.Monoid.RightAction (RightAction (..), RightTorsor (..))+ -- changeset-lens import Control.Monad.Changeset.Lens.Setter @@ -27,3 +30,23 @@ -- | Create a changeset that changes those parts of a state which are traversed traversalChangeset :: Traversal' s a -> w -> SetterChangeset s a w traversalChangeset t w = setterChangeset t w++-- | Given a setter, change the part of the state it focusses.+changing :: (RightAction w a) => Setter' s a -> s -> w -> s+changing setter s w = over setter (`actRight` w) s++-- | Apply a change to each focussed value.+changed :: (RightAction w s) => w -> Fold s s+changed w = to (`actRight` w)++{- | Witness the isomorphism between state and torsor change.++A torsor change is a similar type to the state, but without a base point.+Given such a base point, a state value is converted to the change by 'differenceRight',+and a change is converted to a state value by 'actRight'.++In other words, when you fix a base state value,+this isomorphism will translate to and from the change necessary to apply to the base state to get to the given state.+-}+relativeTo :: (RightTorsor w s) => s -> Iso' s w+relativeTo sReference = iso (differenceRight sReference) (actRight sReference)