packages feed

focus 1.0.2 → 1.0.3

raw patch · 4 files changed

+57/−5 lines, 4 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Focus: accessAndAdjust :: Monad m => (s -> a) -> (s -> s) -> Focus s m (Maybe a)
+ Focus: liftState :: Monad m => State s a -> Focus s m (Maybe a)
+ Focus: liftStateFn :: Monad m => (s -> (a, s)) -> Focus s m (Maybe a)

Files

focus.cabal view
@@ -1,5 +1,5 @@ name: focus-version: 1.0.2+version: 1.0.3 synopsis: A general abstraction for manipulating elements of container data structures description:   An API for construction of free-form strategies of access and manipulation of 
library/Focus.hs view
@@ -73,7 +73,7 @@  {-| Reproduces the behaviour of-@Data.Map.<http://hackage.haskell.org/package/containers-0.6.0.1/docs/Data-Map-Lazy.html#v:lookup lookup>@.+@Data.Map.<http://hackage.haskell.org/package/containers-0.6.0.1/docs/Data-Map-Lazy.html#v:member member>@. -} {-# INLINE member #-} member :: Monad m => Focus a m Bool@@ -142,7 +142,7 @@ -} {-# INLINE alter #-} alter :: Monad m => (Maybe a -> Maybe a) -> Focus a m ()-alter fn = unitCases (maybe Leave Set (fn Nothing)) (maybe Leave Set . fn . Just)+alter fn = unitCases (maybe Leave Set (fn Nothing)) (maybe Remove Set . fn . Just)  {-| Reproduces the behaviour of@@ -160,6 +160,33 @@ update :: Monad m => (a -> Maybe a) -> Focus a m () update fn = unitCases Leave (maybe Remove Set . fn) +{-|+Same as all of the following expressions:++@\f g -> fmap (fmap f) lookup <* adjust g@+@\f g -> liftStateFn (f &&& g)@+@\f g -> liftStateFn ((,) <$> f <*> g)@+-}+accessAndAdjust :: Monad m => (s -> a) -> (s -> s) -> Focus s m (Maybe a)+accessAndAdjust f g =+  liftStateFn (f &&& g)++{-|+Lift a pure state monad.+-}+liftState :: Monad m => State s a -> Focus s m (Maybe a)+liftState (StateT fn) =+  liftStateFn (runIdentity . fn)++{-|+Lift a pure state-monad-like function.+-}+liftStateFn :: Monad m => (s -> (a, s)) -> Focus s m (Maybe a)+liftStateFn fn =+  Focus+    (return (Nothing, Leave))+    (\s -> case fn s of (a, s) -> return (Just a, Set s))+ -- ** Construction utils ------------------------- @@ -213,7 +240,7 @@ -} {-# INLINE alterM #-} alterM :: Monad m => (Maybe a -> m (Maybe a)) -> Focus a m ()-alterM fn = unitCasesM (fmap (maybe Leave Set) (fn Nothing)) (fmap (maybe Leave Set) . fn . Just)+alterM fn = unitCasesM (fmap (maybe Leave Set) (fn Nothing)) (fmap (maybe Remove Set) . fn . Just)  {-| A monadic version of 'adjust'.@@ -227,7 +254,7 @@ -} {-# INLINE updateM #-} updateM :: Monad m => (a -> m (Maybe a)) -> Focus a m ()-updateM fn = unitCasesM (return Leave) (fmap (maybe Leave Set) . fn)+updateM fn = unitCasesM (return Leave) (fmap (maybe Remove Set) . fn)  -- ** Construction utils -------------------------
library/Focus/Prelude.hs view
@@ -71,4 +71,13 @@  -- transformers -------------------------+import Control.Monad.IO.Class as Exports import Control.Monad.Trans.Class as Exports+import Control.Monad.Trans.Cont as Exports hiding (shift, callCC)+import Control.Monad.Trans.Except as Exports (ExceptT(ExceptT), Except, except, runExcept, runExceptT, mapExcept, mapExceptT, withExcept, withExceptT, throwE, catchE)+import Control.Monad.Trans.Maybe as Exports+import Control.Monad.Trans.Reader as Exports (Reader, ask, runReader, mapReader, withReader, ReaderT(ReaderT), runReaderT, mapReaderT, withReaderT)+import Control.Monad.Trans.State.Strict as Exports (State, runState, evalState, execState, mapState, withState, StateT(StateT), runStateT, evalStateT, execStateT, mapStateT, withStateT)+import Control.Monad.Trans.Writer.Strict as Exports (Writer, runWriter, execWriter, mapWriter, WriterT(..), execWriterT, mapWriterT)+import Data.Functor.Compose as Exports+import Data.Functor.Identity as Exports
test/Main.hs view
@@ -42,10 +42,26 @@         assertEqual "" ((), Focus.Set "one") (runIdentity (present "zero"))         assertEqual "" ((), Focus.Set "one") (runIdentity absent)     ,+    testCase "alter" $ let+      f :: Maybe String -> Maybe String+      f = const Nothing+      Focus.Focus absent present = Focus.alter f+      in do+        assertEqual "" ((), Focus.Remove) (runIdentity (present "zero"))+        assertEqual "" ((), Focus.Leave) (runIdentity absent)+    ,     testCase "update" $ let       f :: String -> Maybe String       f = const Nothing       Focus.Focus absent present = Focus.update f+      in do+        assertEqual "" ((), Focus.Remove) (runIdentity (present "zero"))+        assertEqual "" ((), Focus.Leave) (runIdentity absent)+    ,+    testCase "updateM" $ let+      f :: String -> Identity (Maybe String)+      f = const (pure Nothing)+      Focus.Focus absent present = Focus.updateM f       in do         assertEqual "" ((), Focus.Remove) (runIdentity (present "zero"))         assertEqual "" ((), Focus.Leave) (runIdentity absent)