hreader-lens-0.1.3.0: Optics for hreader package

Safe HaskellNone
LanguageHaskell2010

Control.Lens.HReader

Description

Optic counterparts of MonadReader combinators from the lens library.

|

Synopsis

Documentation

hreader :: (MonadHReader m, HGettable (MHRElements m) s) => (s -> a) -> m a #

hasks :: (MonadHReader m, HGettable (MHRElements m) s) => (s -> a) -> m a #

hview :: (MonadHReader m, HGettable (MHRElements m) s) => Getting a s a -> m a #

hviews :: (MonadHReader m, HGettable (MHRElements m) s) => LensLike' (Const r) s a -> (a -> r) -> m r #

hiview :: (MonadHReader m, HGettable (MHRElements m) s) => IndexedGetting i (i, a) s a -> m (i, a) #

hperform :: (MonadHReader m, HGettable (MHRElements m) r) => (s -> r -> m a) -> IndexPreservingAction m s a #

It actually semantically similar to a mix of hask and act, performing the monadic action on s taken from the optic composition on the left and r from HReader on the right. @

type A = Int type B = Int

data R = R { _baz :: B }

makeLenses ''R

foo :: IO Int foo = runHReaderT (HSCons (3::A) HSNil) f where f :: HReaderT '[Int] IO B f = R 3 ^! baz . hperform g . baz g :: B -> A -> HReaderT '[Int] IO R g = x y -> pure (R (x * y)) @

hperforml :: (MonadHReader m, HGettable (MHRElements m) r) => (r -> s -> m a) -> IndexPreservingAction m s a #

Flipped version of hperform