ThoughtWorksInc / each

A macro library that converts native imperative syntax to scalaz's monadic expressions
Apache License 2.0
255 stars 25 forks source link

Support cats.Monad #44

Open Atry opened 7 years ago

Atry commented 1 year ago

Implemented in https://github.com/ThoughtWorksInc/dsl-domains-cats

ScalaWilliam commented 1 year ago

@Atry I don't quite understand, how do you use each with cats? Tried some imports but could not get them to work together.

ScalaWilliam commented 1 year ago

For those interested, this solution worked for me:


    implicit val monadR: scalaz.Monad[Resource[IO, *]] =
      new Monad[Resource[IO, *]] {
        override def point[A](a: => A): Resource[IO, A] = cats.effect.Resource
          .pure(a)

        override def bind[A, B](
            fa: Resource[IO, A],
        )(f: A => Resource[IO, B]): Resource[IO, B] = fa.flatMap(f)
      }

    import com.thoughtworks.each.Monadic._

    monadic[Resource[IO, *]] {
// ...

IO:

  private implicit val monadR: scalaz.Monad[IO] = new scalaz.Monad[IO] {
    override def bind[A, B](fa: IO[A])(f: A => IO[B]): IO[B] = fa.flatMap(f)

    override def point[A](a: => A): IO[A] = IO.delay(a)
  }
Atry commented 1 year ago

To be clear, each does not support cats. I just mean I created another similar library that supports cats.

(reopen this issue so that people could find the solution in dsl-domains-cats easier)