-
Notifications
You must be signed in to change notification settings - Fork 11
Open
Labels
kind/questionQuestions about existing featuresQuestions about existing features
Description
For 🐱 lovers out there, how about including cats instances in the besom-cats package?
allows for compact syntax like role >> roleBinding >> service
import besom.{Context, Output}
import cats.Functor
object CatsInstances {
implicit val outputFunctor: Functor[Output] = new cats.Functor[Output] {
def map[A, B](fa: Output[A])(f: A => B): Output[B] = fa.map(f)
}
implicit def outputApplicative(implicit context: Context): cats.Applicative[Output] = new cats.Applicative[Output] {
def pure[A](x: A): Output[A] = Output(x)
def ap[A, B](ff: Output[A => B])(fa: Output[A]): Output[B] = fa.flatMap(a => ff.map(f => f(a)))
}
implicit def outputMonad(implicit context: Context): cats.Monad[Output] = new cats.Monad[Output] {
def flatMap[A, B](fa: Output[A])(f: A => Output[B]): Output[B] = fa.flatMap(f)
def pure[A](x: A): Output[A] = Output(x)
def tailRecM[A, B](a: A)(f: A => Output[Either[A, B]]): Output[B] =
f(a).flatMap {
case Left(a1) => tailRecM(a1)(f)
case Right(b) => Output(b)
}
}
}(the tailrec might need an actual implementation, which probably requires access to internals)
Metadata
Metadata
Assignees
Labels
kind/questionQuestions about existing featuresQuestions about existing features