packages feed

optics-extra 0.1 → 0.2

raw patch · 9 files changed

+82/−24 lines, 9 filesdep +indexed-profunctorsdep ~optics-corePVP ok

version bump matches the API change (PVP)

Dependencies added: indexed-profunctors

Dependency ranges changed: optics-core

API changes (from Hackage documentation)

- Optics.View: listening :: (ViewableOptic k r, MonadWriter s m) => Optic' k is s r -> m a -> m (a, ViewResult k r)
- Optics.View: listenings :: (ViewableOptic k r, MonadWriter s m) => Optic' k is s a -> (a -> r) -> m b -> m (b, ViewResult k r)
- Optics.View: use :: (ViewableOptic k a, MonadState s m) => Optic' k is s a -> m (ViewResult k a)
- Optics.View: uses :: (ViewableOptic k r, MonadState s m) => Optic' k is s a -> (a -> r) -> m (ViewResult k r)
+ Optics.At: -- <a>An_AffineTraversal</a>, <tt>Representable</tt> (Naperian)
+ Optics.At: -- <tt>A_Traversal</tt>.
+ Optics.At: -- containers it is <a>A_Lens</a>, and multi-maps would have
+ Optics.At: -- of optic to index into it. For most containers, it's
+ Optics.At: -- | Type family that takes a key-value container type and returns the kind
+ Optics.At: }
+ Optics.State: preuse :: (Is k An_AffineFold, MonadState s m) => Optic' k is s a -> m (Maybe a)
+ Optics.State: use :: (Is k A_Getter, MonadState s m) => Optic' k is s a -> m a
+ Optics.View: glistening :: (ViewableOptic k r, MonadWriter s m) => Optic' k is s r -> m a -> m (a, ViewResult k r)
+ Optics.View: glistenings :: (ViewableOptic k r, MonadWriter s m) => Optic' k is s a -> (a -> r) -> m b -> m (b, ViewResult k r)
+ Optics.View: guse :: (ViewableOptic k a, MonadState s m) => Optic' k is s a -> m (ViewResult k a)
+ Optics.View: guses :: (ViewableOptic k r, MonadState s m) => Optic' k is s a -> (a -> r) -> m (ViewResult k r)
- Optics.At: class Ixed m => At m
+ Optics.At: class (Ixed m, IxKind m ~ An_AffineTraversal) => At m
- Optics.At: class Ixed m
+ Optics.At: class Ixed m where {
- Optics.At: ix :: Ixed m => Index m -> AffineTraversal' m (IxValue m)
+ Optics.At: ix :: Ixed m => Index m -> Optic' (IxKind m) NoIx m (IxValue m)
- Optics.At: type family IxValue m :: Type
+ Optics.At: type family IxKind m :: OpticKind;

Files

+ CHANGELOG.md view
@@ -0,0 +1,9 @@+# optics-extra-0.1 (2019-10-18)+* Move `use` from `Optics.View` to `Optics.State` and restrict its type+* Add `preuse` to `Optics.State`+* Rename `use`, `uses`, `listening` and `listenings` to reflect the fact that+  they have `ViewResult`-generalised types+* Depend on new `indexed-profunctors` package++# optics-extra-0.1 (2019-09-02)+* Initial release
optics-extra.cabal view
@@ -1,19 +1,24 @@ name:          optics-extra-version:       0.1+version:       0.2 license:       BSD3 license-file:  LICENSE build-type:    Simple cabal-version: 1.24 maintainer:    optics@well-typed.com author:        Andrzej Rybczak-tested-with:   ghc ==8.0.2 || ==8.2.2 || ==8.4.4 || ==8.6.5 || ==8.8.1+tested-with:   ghc ==8.0.2 || ==8.2.2 || ==8.4.4 || ==8.6.5 || ==8.8.1, GHCJS ==8.4 synopsis:      Extra utilities and instances for optics-core category:      Data, Optics, Lenses description:   This package provides extra definitions and instances that extend the-  @optics-core@ package, without incurring too many dependencies.  See the-  @optics@ package for more documentation.+  @<https://hackage.haskell.org/package/optics-core optics-core>@ package,+  without incurring too many dependencies.  See the+  @<https://hackage.haskell.org/package/optics optics>@ package for more+  documentation. +extra-doc-files:+  CHANGELOG.md+ bug-reports:   https://github.com/well-typed/optics/issues source-repository head   type:     git@@ -30,8 +35,9 @@                , bytestring             >= 0.10.8    && <0.11                , containers             >= 0.5.7.1   && <0.7                , hashable               >= 1.1.1     && <1.4+               , indexed-profunctors    >= 0.1       && <0.2                , mtl                    >= 2.2.2     && <2.3-               , optics-core            >= 0.1       && <1.0+               , optics-core            >= 0.2       && <0.2.1                , text                   >= 1.2       && <1.3                , transformers           >= 0.5       && <0.6                , unordered-containers   >= 0.2.6     && <0.3
src/Data/Text/Lazy/Optics.hs view
@@ -26,12 +26,13 @@ import Data.Text.Lazy.Builder import Data.Text.Lazy.Encoding +import Data.Profunctor.Indexed+ import Optics.Core import Optics.Internal.Fold import Optics.Internal.IxFold import Optics.Internal.IxTraversal import Optics.Internal.Optic-import Optics.Internal.Profunctor  -- | This isomorphism can be used to 'pack' (or 'unpack') lazy 'Text.Text'. --
src/Data/Text/Strict/Optics.hs view
@@ -27,12 +27,13 @@ import Data.Text.Lazy (toStrict) import Data.Text.Lazy.Builder +import Data.Profunctor.Indexed+ import Optics.Core import Optics.Internal.Fold import Optics.Internal.IxFold import Optics.Internal.IxTraversal import Optics.Internal.Optic-import Optics.Internal.Profunctor  -- | This isomorphism can be used to 'pack' (or 'unpack') strict 'Strict.Text'. --
src/Data/Vector/Generic/Optics.hs view
@@ -22,11 +22,12 @@ import Data.Vector.Generic.New (New) import Prelude hiding ((++), length, null, head, tail, init, last, map, reverse) +import Data.Profunctor.Indexed+ import Optics.Core import Optics.Extra.Internal.Vector import Optics.Internal.Fold import Optics.Internal.IxFold-import Optics.Internal.Profunctor import Optics.Internal.Optic  -- | @sliced i n@ provides a 'Lens' that edits the @n@ elements starting at
src/Optics/Extra/Internal/ByteString.hs view
@@ -27,11 +27,12 @@ import qualified Data.ByteString.Internal   as BI import qualified Data.ByteString.Unsafe     as BU +import Data.Profunctor.Indexed+ import Optics.Core import Optics.Internal.Fold import Optics.Internal.IxFold import Optics.Internal.Optic-import Optics.Internal.Profunctor  -- | Traverse a strict 'B.ByteString' in a relatively balanced fashion, as a -- balanced tree with biased runs of elements at the leaves.
src/Optics/State.hs view
@@ -11,6 +11,8 @@   , modifying'   , assign   , assign'+  , use+  , preuse   ) where  import Control.Monad.State@@ -79,6 +81,34 @@   -> m () assign' o = modifying' o . const {-# INLINE assign' #-}++-- | Use the target of a 'Lens', 'Iso', or 'Getter' in the current state.+--+-- >>> evalState (use _1) ('a','b')+-- 'a'+--+-- >>> evalState (use _2) ("hello","world")+-- "world"+--+use+  :: (Is k A_Getter, MonadState s m)+  => Optic' k is s a+  -> m a+use o = gets (view o)+{-# INLINE use #-}++-- | Use the target of a 'AffineTraveral' or 'AffineFold' in the current state.+--+-- >>> evalState (preuse $ _1 % _Right) (Right 'a','b')+-- Just 'a'+--+-- @since 0.2+preuse+  :: (Is k An_AffineFold, MonadState s m)+  => Optic' k is s a+  -> m (Maybe a)+preuse o = gets (preview o)+{-# INLINE preuse #-}  -- $setup -- >>> import Data.Semigroup
src/Optics/View.hs view
@@ -103,56 +103,64 @@ -- | Use the target of a 'Lens', 'Iso', or 'Getter' in the current state, or use -- a summary of a 'Fold' or 'Traversal' that points to a monoidal value. ----- >>> evalState (use _1) ('a','b')+-- >>> evalState (guse _1) ('a','b') -- 'a' ----- >>> evalState (use _2) ("hello","world")+-- >>> evalState (guse _2) ("hello","world") -- "world"-use+--+-- @since 0.2+guse   :: (ViewableOptic k a, MonadState s m)   => Optic' k is s a   -> m (ViewResult k a)-use o = gets (gview o)-{-# INLINE use #-}+guse o = gets (gview o)+{-# INLINE guse #-}  -- | Use the target of a 'Lens', 'Iso' or 'Getter' in the current state, or use -- a summary of a 'Fold' or 'Traversal' that points to a monoidal value. ----- >>> evalState (uses _1 length) ("hello","world")+-- >>> evalState (guses _1 length) ("hello","world") -- 5-uses+--+-- @since 0.2+guses   :: (ViewableOptic k r, MonadState s m)   => Optic' k is s a   -> (a -> r)   -> m (ViewResult k r)-uses o f = gets (gviews o f)-{-# INLINE uses #-}+guses o f = gets (gviews o f)+{-# INLINE guses #-}  -- | This is a generalized form of 'listen' that only extracts the portion of -- the log that is focused on by a 'Getter'. If given a 'Fold' or a 'Traversal' -- then a monoidal summary of the parts of the log that are visited will be -- returned.-listening+--+-- @since 0.2+glistening   :: (ViewableOptic k r, MonadWriter s m)   => Optic' k is s r   -> m a   -> m (a, ViewResult k r)-listening o m = do+glistening o m = do   (a, w) <- listen m   return (a, gview o w)-{-# INLINE listening #-}+{-# INLINE glistening #-}  -- | This is a generalized form of 'listen' that only extracts the portion of -- the log that is focused on by a 'Getter'. If given a 'Fold' or a 'Traversal' -- then a monoidal summary of the parts of the log that are visited will be -- returned.-listenings+--+-- @since 0.2+glistenings   :: (ViewableOptic k r, MonadWriter s m)   => Optic' k is s a   -> (a -> r)   -> m b   -> m (b, ViewResult k r)-listenings o f m = do+glistenings o f m = do   (a, w) <- listen m   return (a, gviews o f w)-{-# INLINE listenings #-}+{-# INLINE glistenings #-}
src/Optics/Zoom.hs view
@@ -407,5 +407,6 @@  -- $setup -- >>> import Data.Monoid+-- >>> import Optics.State -- >>> import Optics.State.Operators -- >>> import Optics.View