Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'etaReaderT' function #233

Closed
chshersh opened this issue Nov 26, 2019 · 0 comments · Fixed by #272
Closed

Add 'etaReaderT' function #233

chshersh opened this issue Nov 26, 2019 · 0 comments · Fixed by #272
Assignees
Labels
new Bring something new into library (add function or type or interface)

Comments

@chshersh
Copy link
Contributor

This function is introduced in the following blog post and helps with optimizing Haskell code:

It has the following defintion:

etaReaderT :: ReaderT r m a -> ReaderT r m a
etaReaderT = ReaderT . oneShot . runReaderT

It can be used if the code like on the snippet below is called in a loop multiple times:

step :: Instr -> ReaderT Config IO Result
step e = case e of
    Add -> do stuff 
    Del -> do stuff 

You just do:

step :: Instr -> ReaderT Config IO Result
step e = etaReaderT $ case e of
    Add ->  do stuff 
    Del ->  do stuff 
@chshersh chshersh added the new Bring something new into library (add function or type or interface) label Nov 26, 2019
@chshersh chshersh added this to the v0.7.0.0: Refiner milestone Feb 25, 2020
@chshersh chshersh self-assigned this May 11, 2020
@chshersh chshersh changed the title [RFC] Add 'etaReaderT' function Add 'etaReaderT' function May 11, 2020
chshersh added a commit that referenced this issue May 11, 2020
vrom911 added a commit that referenced this issue May 11, 2020
* [#233] Add 'etaReaderT' function

Resolves #233

* Update src/Relude/Monad/Trans.hs

Co-authored-by: Veronika Romashkina <vrom911@gmail.com>

* Use CPP for etaReaderT

Co-authored-by: Veronika Romashkina <vrom911@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new Bring something new into library (add function or type or interface)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant