Open MansurAshraf opened 7 years ago
I think this is a great idea.
Of course, I will likely not get to it very soon. Something like:
trait BijectionK[F[_], G[_]] {
def apply[A](f: F[A]): G[A]
def invert[A](g: G[A]): F[A]
def toBijection[A]: Bijection[F[A], G[A]]
}
trait InjectionK[F[_], G[_]] {
def apply[A](f: F[A]): G[A]
def invert[A](g: G[A]): Try[F[A]]
def toInjection[A]: Injection[F[A], G[A]]
}
and of course laws.
Maybe add FunctionK
while we are at it, but maybe not actually needed... not clear.
Cats have InjectionK but their
invert
function returnsOption[F[_]]
which they are unwilling to change. It would nice to have InjectionK withinvert
defined asTry[F[_]]
as we have for all our existing injections. WhileOption[F[_]]
maybe more theoretically correct, I have foundTry[F[_]]
to be more useful as I usually want to do something with he exception when inversion fails!. We would also needFunctionK
as well