tofu.higherKind.bi.BiRepresentableK.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of tofu-core-higher-kind_3 Show documentation
Show all versions of tofu-core-higher-kind_3 Show documentation
Opinionated set of tools for functional programming in Scala
package tofu.higherKind.bi
import tofu.control.Bind
import tofu.higherKind.bi.RepresentableB.Tab
trait RepresentableB[U[f[_, _]]] extends MonoidalBK[U] with EmbedBK[U] {
def bitabulate[F[_, _]](repr: RepBK[U, _, _] FunBK F): U[F]
final def tab[F[_, _]]: Tab[U, F] = new Tab(this)
def biembed[F[_, _]](fu: F[U[F], U[F]])(implicit F: Bind[F]): U[F] =
tab[F](repr => F.foldWithC(fu)(repr(_))(repr(_)))
def map2b[F[_, _], G[_, _], H[_, _]](uf: U[F], ug: U[G])(fk: Fun2BK[F, G, H]): U[H] =
tab[H](repr => fk(repr(uf), repr(ug)))
def pureB[F[_, _]](point: BiPoint[F]): U[F] = tab[F](_ => point.apply)
}
object RepresentableB {
def apply[U[f[_, _]]](implicit u: RepresentableB[U]): RepresentableB[U] = u
class Tab[U[f[_, _]], F[_, _]](private val repr: RepresentableB[U]) extends AnyVal {
type E1
type A1
def apply(maker: FunBK.Maker[RepBK[U, _, _], F, E1, A1]): U[F] = repr.bitabulate(maker)
}
}