packages feed

microlens-mtl 0.1.7.1 → 0.1.8.0

raw patch · 3 files changed

+92/−3 lines, 3 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

+ Lens.Micro.Mtl: (<%=) :: MonadState s m => LensLike ((,) b) s s a b -> (a -> b) -> m b
+ Lens.Micro.Mtl: (<<%=) :: MonadState s m => LensLike ((,) a) s s a b -> (a -> b) -> m a
+ Lens.Micro.Mtl: (<<.=) :: MonadState s m => LensLike ((,) a) s s a b -> b -> m a
+ Lens.Micro.Mtl: assign :: MonadState s m => ASetter s s a b -> b -> m ()
+ Lens.Micro.Mtl: modifying :: (MonadState s m) => ASetter s s a b -> (a -> b) -> m ()
- Lens.Micro.Mtl: infix 4 //=
+ Lens.Micro.Mtl: infix 4 <<.=

Files

CHANGELOG.md view
@@ -1,3 +1,8 @@+# 0.1.8.0++* Added `assign` and `modifying` as synonyms for `.=` and `%=`.+* Added `<%=`, `<<%=`, and `<<.=`.+ # 0.1.7.1  * Added forgotten copyright/authorship information.
microlens-mtl.cabal view
@@ -1,5 +1,5 @@ name:                microlens-mtl-version:             0.1.7.1+version:             0.1.8.0 synopsis:            microlens support for Reader/Writer/State from mtl description:   This package contains functions (like 'view' or '+=') which work on 'MonadReader', 'MonadWriter', and 'MonadState' from the mtl package.
src/Lens/Micro/Mtl.hs view
@@ -1,4 +1,5 @@ {-# LANGUAGE+CPP, MultiParamTypeClasses, FunctionalDependencies, FlexibleInstances,@@ -18,12 +19,22 @@ -} module Lens.Micro.Mtl (+  -- * Getting   view, preview,   use, preuse,++  -- * Zooming   zoom,   magnify,-  (.=), (%=),++  -- * Setting+  (.=), assign,+  (%=), modifying,   (+=), (-=), (*=), (//=),++  -- * Setting with passthrough+  (<%=), (<<%=),+  (<<.=), ) where @@ -104,6 +115,7 @@   infix  4 .=, %=+infix  4 <<.=, <<%=, <%= infix  4 +=, -=, *=, //=  {- |@@ -114,12 +126,21 @@ @ l '.=' x = 'State.modify' (l '.~' x) @++If you also want to know the value that was replaced by ('.='), use ('<<.='). -} (.=) :: MonadState s m => ASetter s s a b -> b -> m () l .= x = State.modify (l .~ x) {-# INLINE (.=) #-}  {- |+A synonym for ('.=').+-}+assign :: MonadState s m => ASetter s s a b -> b -> m ()+assign l x = l .= x+{-# INLINE assign #-}++{- | Modify state by applying a function to a part of the state. An example:  >>> execState (do _1 %= (+1); _2 %= reverse) (1,"hello")@@ -131,8 +152,10 @@ l '%=' f = 'State.modify' (l '%~' f) @ -There are also a few specialised versions of ('%=') which mimic C operators:+If you also want to get the value before\/after the modification, use ('<<%=')\/('<%='). +There are a few specialised versions of ('%=') which mimic C operators:+ * ('+=') for addition * ('-=') for substraction * ('*=') for multiplication@@ -143,6 +166,13 @@ {-# INLINE (%=) #-}  {- |+A synonym for ('%=').+-}+modifying :: (MonadState s m) => ASetter s s a b -> (a -> b) -> m ()+modifying l f = l %= f+{-# INLINE modifying #-}++{- | Add a number to the target.  @@@ -185,3 +215,57 @@ (//=) :: (MonadState s m, Fractional a) => ASetter s s a a -> a -> m () l //= x = l %= (/x) {-# INLINE (//=) #-}++{- |+Modify state and return the modified (new) value.++@+l '<%=' f = do+  l '%=' f+  'use' l+@+-}+(<%=) :: MonadState s m => LensLike ((,) b) s s a b -> (a -> b) -> m b+l <%= f = l %%= (\a -> (a, a)) . f+{-# INLINE (<%=) #-}++{- |+Modify state and return the old value (i.e. as it was before the modificaton).++@+l '<<%=' f = do+  old <- 'use' l+  l '%=' f+  return old+@+-}+(<<%=) :: MonadState s m => LensLike ((,) a) s s a b -> (a -> b) -> m a+l <<%= f = l %%= (\a -> (a, f a))+{-# INLINE (<<%=) #-}++{- |+Set state and return the old value.++@+l '<<.=' b = do+  old <- 'use' l+  l '.=' f+  return old+@+-}+(<<.=) :: MonadState s m => LensLike ((,) a) s s a b -> b -> m a+l <<.= b = l %%= (\a -> (a, b))+{-# INLINE (<<.=) #-}++(%%=) :: MonadState s m => LensLike ((,) r) s s a b -> (a -> (r, b)) -> m r+#if MIN_VERSION_mtl(2,1,1)+l %%= f = State.state (l f)+#else+l %%= f = do+  (r, s) <- State.gets (l f)+  State.put s+  return r+#endif+{-# INLINE (%%=) #-}++infix 4 %%=