cats icon indicating copy to clipboard operation
cats copied to clipboard

FreeT.inject helper function

Open VledicFranco opened this issue 9 years ago • 2 comments

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! :)

VledicFranco avatar Feb 10 '17 12:02 VledicFranco

Is this issue still open? If so, what exactly is required? I'd like to contribute. :)

njayinthehouse avatar Oct 04 '17 15:10 njayinthehouse

Seems to have been fixed by https://github.com/typelevel/cats/pull/2169

kubukoz avatar Apr 15 '18 14:04 kubukoz