Skip to content

Commit

Permalink
Implicit conversion from Bind to cats.Monad (#798)
Browse files Browse the repository at this point in the history
* Implicit conversion from Bind to cats.Monad

From user perspective, when I require Bind instance in my code,
I want to have implicit cats.Monad instance for later usages. Now to do so
I have to write something like implicit def monad[E] = bind.monad[E]
in the beginning of the method, since most of the library methods accept
typeclasses as implicit parameters.

Assuming that Bind is right-biased, it makes perfect sense to write such
implicit conversion and use it in source file imports section.

* Fix naming
  • Loading branch information
gzoom13 committed Oct 5, 2021
1 parent 2fd2054 commit dfe0d0a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package tofu.instances

import cats.Monad
import tofu.control.Bind

object bind {
implicit def monadFromBind[F[+_, +_], E](implicit bind: Bind[F]): Monad[F[E, *]] = bind.monad
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package tofu.control

import cats.{Applicative, FlatMap}
import tofu.compat.unused
import tofu.instances.bind._

class CatsInstancesFromBindSuite {
def summonBindInstances[F[+_, +_]](implicit bind: Bind[F]): Unit = {
requireApplicative[F[Throwable, *]]
requireFlatMap[F[Nothing, *]]
}

def requireApplicative[F[_]](implicit @unused applicative: Applicative[F]): Unit = ()

def requireFlatMap[F[_]](implicit @unused flatMap: FlatMap[F]): Unit = ()
}

0 comments on commit dfe0d0a

Please sign in to comment.