ManagedT: a monad for resource management

ManagedT[F[_], A] is a monad for constructing computations that acquire and release resources. It is a translation of Gabriel Gonzalez' managed library, with the difference that this library abstracts over the effect type.

This library only contains typeclass instances for cats. Scalaz already contains the Codensity data type which can serve the same functionality (with, albeit, some additional plumbing for cleanup handlers).

IMPORTANT CAVEATS

This library supports any F[_] that has MonadError[F, Throwable]. That includes monix.eval.Task, cats.effect.IO, scala.concurrent.Future (and others).

However, it is very likely to be broken if:

you use cancellation with Task or IO - MonadError is not strong enough to express bracketing with cancellation, so that'll have to wait for MonadBracket in cats-effect;

you use it with a monad transformer such as EitherT[IO, E, A], where there are several "layers" in which errors could be thrown;

you throw exceptions in the acquire or cleanup actions that are not sequenced into the F[_];

you pass Future values that have already been executed in the acquire or cleanup functions. The library has constructors with by-name values in most places to assist with that.

Other than that, it's all good ;-) The test suite exercises the common usecases; you are welcome to have a look.