fused-effects-optics 0.1.0.0 → 0.2.0.0
raw patch · 4 files changed
+78/−14 lines, 4 filesdep ~basePVP ok
version bump matches the API change (PVP)
Dependency ranges changed: base
API changes (from Hackage documentation)
- Control.Effect.Optics: eview :: forall r a m sig k is. (Is k A_Getter, Has (Reader r) sig m) => Optic' k is r a -> m a
- Control.Effect.Optics: eviews :: forall r a b m sig k is. (Is k A_Getter, Has (Reader r) sig m) => Optic' k is r a -> (a -> b) -> m b
+ Control.Effect.Optics: locally :: (Is k A_Setter, Has (Reader r) sig m) => Optic k is r r a b -> (a -> b) -> m c -> m c
+ Control.Effect.Optics: view :: forall r a m sig k is. (Is k A_Getter, Has (Reader r) sig m) => Optic' k is r a -> m a
+ Control.Effect.Optics: views :: forall r a b m sig k is. (Is k A_Getter, Has (Reader r) sig m) => Optic' k is r a -> (a -> b) -> m b
+ Control.Effect.Optics.Indexed: ilocally :: (Has (Reader s) sig m, is `HasSingleIndex` i, Is k A_Setter) => Optic k is s s a1 b -> (i -> a1 -> b) -> m a2 -> m a2
+ Control.Effect.Optics.Indexed: iuse :: (Is k A_Getter, is `HasSingleIndex` i, Has (State s) sig m) => Optic' k is s a -> m (i, a)
+ Control.Effect.Optics.Indexed: iuses :: (Is k A_Getter, is `HasSingleIndex` i, Has (State s) sig m) => Optic' k is s a -> (i -> a -> m b) -> m b
+ Control.Effect.Optics.Indexed: iview :: (Is k A_Getter, is `HasSingleIndex` i, Has (Reader r) sig m) => Optic' k is r a -> m (i, a)
+ Control.Effect.Optics.Indexed: iviews :: (Is k A_Getter, is `HasSingleIndex` i, Has (Reader r) sig m) => Optic' k is r a -> (i -> a -> m b) -> m b
Files
- CHANGELOG.md +7/−0
- fused-effects-optics.cabal +3/−2
- src/Control/Effect/Optics.hs +28/−12
- src/Control/Effect/Optics/Indexed.hs +40/−0
CHANGELOG.md view
@@ -3,6 +3,13 @@ `fused-effects-optics` uses [PVP Versioning][1]. The changelog is available [on GitHub][2]. +## 0.0.2.0++* GHC 9 support.+* Add `Control.Effect.Optics.Indexed` module.+* `eview` and `eviews` are renamed to `view` and `views`.+* Added `locally`.+ ## 0.0.1.0 * Initially created.
fused-effects-optics.cabal view
@@ -1,6 +1,6 @@ cabal-version: 2.2 name: fused-effects-optics-version: 0.1.0.0+version: 0.2.0.0 synopsis: Bridge between the optics and fused-effects ecosystems. description: Provides combinators for the optics-based manipulation of state and context types provided by the fused-effects library, similar to those provided by optics-extra for mtl-based monad transformers. homepage: https://github.com/fused-effects/fused-effects-optics@@ -24,9 +24,10 @@ library hs-source-dirs: src exposed-modules: Control.Effect.Optics+ Control.Effect.Optics.Indexed - build-depends: base >= 4.12 && < 4.15+ build-depends: base >= 4.12 && < 4.16 , fused-effects >= 1 && < 1.2 , optics-core >= 0.3
src/Control/Effect/Optics.hs view
@@ -5,14 +5,17 @@ module Control.Effect.Optics ( -- * Reader operations- eview,- eviews,+ Control.Effect.Optics.view,+ Control.Effect.Optics.views,+ locally,+ -- * State operations use, uses, preuse, assign, modifying,+ -- * Infix operators (.=), (?=),@@ -26,20 +29,21 @@ -- | View the target of a 'Lens', 'Iso', or 'Getter' in the current context. ----- This function is prefixed so as not to collide with 'Optics.Core.view'.----eview ::+-- Because functions implement 'Reader.Reader', you can use this wherever+-- you would use the @view@ function in @optics@, as well as the @gview@+-- operation in @optics-extra@.+view :: forall r a m sig k is. ( Is k A_Getter, Has (Reader.Reader r) sig m ) => Optic' k is r a -> m a-eview l = Reader.asks (view l)-{-# INLINE eview #-}+view l = Reader.asks (Optics.Core.view l)+{-# INLINE view #-} -- | Apply a function to the target of a 'Lens', 'Iso', or 'Getter' in the current context.-eviews ::+views :: forall r a b m sig k is. ( Is k A_Getter, Has (Reader.Reader r) sig m@@ -47,9 +51,21 @@ Optic' k is r a -> (a -> b) -> m b-eviews l f = Reader.asks (f . view l)-{-# INLINE eviews #-}+views l f = Reader.asks (f . Optics.Core.view l)+{-# INLINE views #-} +-- | Given a monadic argument, evaluate it in a context modified by applying+-- the provided function to the target of the provided 'Setter', 'Lens', or 'Traversal'.+locally ::+ ( Is k A_Setter,+ Has (Reader.Reader r) sig m+ ) =>+ Optic k is r r a b ->+ (a -> b) ->+ m c ->+ m c+locally l f = Reader.local (over l f)+ -- | Use the target of a 'Lens', 'Iso', or 'Getter' in the current state. use :: forall s a m sig k is.@@ -58,7 +74,7 @@ ) => Optic' k is s a -> m a-use l = State.gets (view l)+use l = State.gets (Optics.Core.view l) {-# INLINE use #-} -- | Apply a function to the target of a 'Lens', 'Iso', or 'Getter' in the current state.@@ -70,7 +86,7 @@ Optic' k is s a -> (a -> b) -> m b-uses l f = State.gets (f . view l)+uses l f = State.gets (f . Optics.Core.view l) {-# INLINE uses #-} -- | Use the target of a 'AffineTraversal' or 'AffineFold' in the current state.
+ src/Control/Effect/Optics/Indexed.hs view
@@ -0,0 +1,40 @@+{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE TypeOperators #-}++module Control.Effect.Optics.Indexed+ ( -- * Indexed reader operations+ iview,+ iviews,+ ilocally,++ -- * Indexed state operations+ iuse,+ iuses,+ )+where++import Control.Effect.Reader as Reader+import Control.Effect.State as State+import Optics.Core hiding (iview, iviews)+import qualified Optics.Core as Optics++-- | View the index and value of an indexed getter into the current environment as a pair.+iview :: (Is k A_Getter, is `HasSingleIndex` i, Has (Reader.Reader r) sig m) => Optic' k is r a -> m (i, a)+iview l = Reader.asks (Optics.iview l)++-- | View the index and value of an indexed getter into the current environment and pass them to the provided function.+iviews :: (Is k A_Getter, is `HasSingleIndex` i, Has (Reader.Reader r) sig m) => Optic' k is r a -> (i -> a -> m b) -> m b+iviews l f = Reader.ask >>= Optics.iviews l f++-- | Given a monadic argument, evaluate it in a context modified by applying+-- the provided function to the index and target of the provided indexed 'Setter', 'Lens', or 'Traversal'.+ilocally :: (Has (Reader s) sig m, is `HasSingleIndex` i, Is k A_Setter) => Optic k is s s a1 b -> (i -> a1 -> b) -> m a2 -> m a2+ilocally l f = Reader.local (iover l f)++-- | Extract the index and target of an indexed getter in the current state as a pair.+iuse :: (Is k A_Getter, is `HasSingleIndex` i, Has (State s) sig m) => Optic' k is s a -> m (i, a)+iuse l = State.gets (Optics.iview l)++-- | Extract the index and target of an indexed getter in the current state and pass them to the provided function.+iuses :: (Is k A_Getter, is `HasSingleIndex` i, Has (State s) sig m) => Optic' k is s a -> (i -> a -> m b) -> m b+iuses l r = State.get >>= Optics.iviews l r