cats
cats copied to clipboard
FreeT.inject helper function
For a project I am using FreeT with multiple algebras, I noticed that there is no helper functions to inject an algebra into a coproduct of algebras for free transformers, so I wrote one similar to the Free.inject like this:
/**
* This method is used to defer the application of an Inject[F, G]
* instance. The actual work happens in
* `FreeTInjectPartiallyApplied#apply`.
*
* This method exists to allow the `F`, `M` and `G` parameters to be
* bound independently of the `A` parameter below.
*/
def inject[F[_], M[_], G[_]]: FreeTInjectPartiallyApplied[F, M, G] =
new FreeTInjectPartiallyApplied
/**
* Pre-application of an injection to a `F[A]` value for a FreeT
* with applicative `M[_]`.
*/
final class FreeTInjectPartiallyApplied[F[_], M[_], G[_]] {
def apply[A](fa: F[A])(implicit I: Inject[F, G], m: Applicative[M]): FreeT[G, M, A] =
FreeT.liftF[G, M, A](I.inj(fa))
}
It is working and I was wondering if this is a good contribution to the library.
Cheers! :)
Is this issue still open? If so, what exactly is required? I'd like to contribute. :)
Seems to have been fixed by https://github.com/typelevel/cats/pull/2169