packages feed

little-rio 2.0.1 → 3.0.0

raw patch · 2 files changed

+21/−25 lines, 2 filesdep +opticsdep −microlensdep ~little-loggerPVP ok

version bump matches the API change (PVP)

Dependencies added: optics

Dependencies removed: microlens

Dependency ranges changed: little-logger

API changes (from Hackage documentation)

Files

little-rio.cabal view
@@ -1,13 +1,13 @@ cabal-version: 1.12 --- This file has been generated from package.yaml by hpack version 0.35.2.+-- This file has been generated from package.yaml by hpack version 0.37.0. -- -- see: https://github.com/sol/hpack ----- hash: 29a5ac4cb7039c63f9b16ffa254e0100726fd220aa6c7721a65cc7761fc98648+-- hash: 2c34a0cd81d30bbaa6fe452cd9718b33a590ce2ffd05268cfab6f60d7989b54a  name:           little-rio-version:        2.0.1+version:        3.0.0 synopsis:       When you need just the RIO monad description:    Please see the README on GitHub at <https://github.com/ejconlon/little-rio#readme> category:       Control@@ -46,9 +46,9 @@   build-depends:       base >=4.12 && <5     , exceptions >=0.10 && <1-    , little-logger >=1.0.2 && <1.1-    , microlens >=0.4 && <1+    , little-logger >=3.0 && <4     , mtl >=2.2 && <3+    , optics >=0.4 && <1     , primitive >=0.7.0.1 && <1     , resourcet >=1.2.4.2 && <2     , unliftio-core >=0.1 && <1
src/LittleRIO.hs view
@@ -23,7 +23,6 @@   ) where -import Control.Applicative (liftA2) import Control.Monad.Catch (MonadCatch, MonadMask, MonadThrow) import Control.Monad.IO.Class (MonadIO (..)) import Control.Monad.IO.Unlift (MonadUnliftIO (..), UnliftIO, askUnliftIO)@@ -34,9 +33,8 @@ import Control.Monad.Trans.Resource.Internal (unResourceT) import Control.Monad.Writer (MonadWriter (..)) import Data.IORef (IORef, newIORef, readIORef, writeIORef)-import Lens.Micro (Lens')-import Lens.Micro.Extras (view) import LittleLogger (LogActionWrapperM (..), MonadLogger)+import Optics (Lens', equality', view)  newtype RIO env a = RIO {unRIO :: ReaderT env IO a}   deriving newtype@@ -53,10 +51,10 @@     )   deriving (MonadLogger) via LogActionWrapperM env (RIO env) -instance Semigroup a => Semigroup (RIO env a) where+instance (Semigroup a) => Semigroup (RIO env a) where   (<>) = liftA2 (<>) -instance Monoid a => Monoid (RIO env a) where+instance (Monoid a) => Monoid (RIO env a) where   mempty = pure mempty   mappend = (<>) @@ -75,34 +73,34 @@   env <- ask   runRIO env m -unliftRIO :: MonadIO m => env -> m (UnliftIO (RIO env))+unliftRIO :: (MonadIO m) => env -> m (UnliftIO (RIO env)) unliftRIO env = liftIO (runRIO env askUnliftIO) -runRIO :: MonadIO m => env -> RIO env a -> m a+runRIO :: (MonadIO m) => env -> RIO env a -> m a runRIO r m = liftIO (runReaderT (unRIO m) r)  data SomeRef a = SomeRef !(IO a) !(a -> IO ()) -readSomeRef :: MonadIO m => SomeRef a -> m a+readSomeRef :: (MonadIO m) => SomeRef a -> m a readSomeRef (SomeRef x _) = liftIO x -writeSomeRef :: MonadIO m => SomeRef a -> a -> m ()+writeSomeRef :: (MonadIO m) => SomeRef a -> a -> m () writeSomeRef (SomeRef _ x) = liftIO . x -modifySomeRef :: MonadIO m => SomeRef a -> (a -> a) -> m ()+modifySomeRef :: (MonadIO m) => SomeRef a -> (a -> a) -> m () modifySomeRef (SomeRef read' write) f = liftIO (read' >>= write . f)  ioRefToSomeRef :: IORef a -> SomeRef a ioRefToSomeRef ref = SomeRef (readIORef ref) (writeIORef ref) -newSomeRef :: MonadIO m => a -> m (SomeRef a)+newSomeRef :: (MonadIO m) => a -> m (SomeRef a) newSomeRef = liftIO . fmap ioRefToSomeRef . newIORef  class HasStateRef st env | env -> st where   stateRefL :: Lens' env (SomeRef st)  instance HasStateRef a (SomeRef a) where-  stateRefL = id+  stateRefL = equality'  getStateRef :: (HasStateRef st env, MonadReader env m, MonadIO m) => m st getStateRef = do@@ -119,7 +117,7 @@   ref <- asks (view stateRefL)   liftIO (modifySomeRef ref f) -instance HasStateRef st env => MonadState st (RIO env) where+instance (HasStateRef st env) => MonadState st (RIO env) where   get = getStateRef   put = putStateRef @@ -127,7 +125,7 @@   writeRefL :: Lens' env (SomeRef w)  instance HasWriteRef a (SomeRef a) where-  writeRefL = id+  writeRefL = equality'  tellWriteRef :: (HasWriteRef w env, MonadReader env m, MonadIO m, Semigroup w) => w -> m () tellWriteRef value = do@@ -159,19 +157,17 @@  type ResourceMap = InternalState -withResourceMap :: MonadUnliftIO m => (ResourceMap -> m a) -> m a+withResourceMap :: (MonadUnliftIO m) => (ResourceMap -> m a) -> m a withResourceMap inner = runResourceT (withInternalState inner) --- withRunInIO (\run -> runResourceT (ResourceT (run . inner)))- class HasResourceMap env where   resourceMapL :: Lens' env ResourceMap  instance HasResourceMap ResourceMap where-  resourceMapL = id+  resourceMapL = equality' -resourceRIO :: HasResourceMap env => ResourceT IO a -> RIO env a+resourceRIO :: (HasResourceMap env) => ResourceT IO a -> RIO env a resourceRIO m = asks (view resourceMapL) >>= liftIO . unResourceT m -instance HasResourceMap env => MonadResource (RIO env) where+instance (HasResourceMap env) => MonadResource (RIO env) where   liftResourceT = resourceRIO