You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This release removes the ResourceT<M, A> monad-transformer from language-ext and instead moves the functionality into the IO<A> monad. ResourceT required IO to be in the transformer stack and so it really was adding complexity to a feature that's closely linked. This adds a tiny overhead to the IO monad -- the IO monad already carried an environment through its computations, so this doesn't change much -- in the big scheme of things it's likely to bring performance benefits.
Some big improvements because of this:
use and release are now available in the Prelude, which makes them easier to work with (no need for any manual generic arguments), everything is inferable from usage.
Forking an IO computation (launching it on a new thread) automatically creates a local resource environment for the fork and cleans it up when the forked operation is complete.
Repeating an IO computation (repeat(computation)) - will automatically clean up any resources acquired by use in the computation (on each iteration).
Retrying an IO computation (retry(computation)) - will automatically clean up any resources (acquired with use) when the computation fails, that mean retries don't accumulate resources unnecessarily.
New function local(computation) works as a 'super using' -- in that it will automatically clean up any resources acquired with use in the computation. This allows you to create local scopes where you just freely acquire resources and then have a clean-up happen automatically.
By the way, I am open to different names for this, as we already have IO.local for local cancellation contexts and Reader.local for local environments. I'm also open to changing the names of the others. Ideally any name would be a single word so it's easy on the eye. So, nothing like localResource or cleanUp.
New functions bracket(Acq, Use, Err, Fin) and bracket(Acq, Use, Fin) - these are like try \ catch \ finally blocks for more explicit resource usage:
Acq - acquires the resource
Use - uses the resource
Err - is the catch block
Fin - is the finally block
All the usual caveats apply: this is an alpha, this isn't fully tested, use at your own risk.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
This release removes the
ResourceT<M, A>
monad-transformer from language-ext and instead moves the functionality into theIO<A>
monad.ResourceT
requiredIO
to be in the transformer stack and so it really was adding complexity to a feature that's closely linked. This adds a tiny overhead to theIO
monad -- the IO monad already carried an environment through its computations, so this doesn't change much -- in the big scheme of things it's likely to bring performance benefits.Some big improvements because of this:
use
andrelease
are now available in thePrelude
, which makes them easier to work with (no need for any manual generic arguments), everything is inferable from usage.IO
computation (launching it on a new thread) automatically creates a local resource environment for the fork and cleans it up when the forked operation is complete.IO
computation (repeat(computation)
) - will automatically clean up any resources acquired byuse
in the computation (on each iteration).IO
computation (retry(computation)
) - will automatically clean up any resources (acquired withuse
) when the computation fails, that mean retries don't accumulate resources unnecessarily.local(computation)
works as a 'superusing
' -- in that it will automatically clean up any resources acquired withuse
in the computation. This allows you to create local scopes where you just freely acquire resources and then have a clean-up happen automatically.IO.local
for local cancellation contexts andReader.local
for local environments. I'm also open to changing the names of the others. Ideally any name would be a single word so it's easy on the eye. So, nothing likelocalResource
orcleanUp
.bracket(Acq, Use, Err, Fin)
andbracket(Acq, Use, Fin)
- these are liketry
\catch
\finally
blocks for more explicit resource usage:Acq
- acquires the resourceUse
- uses the resourceErr
- is the catch blockFin
- is the finally blockAll the usual caveats apply: this is an alpha, this isn't fully tested, use at your own risk.
This discussion was created from the release Removed ResourceT transformer / integrated into IO.
Beta Was this translation helpful? Give feedback.
All reactions