bijection icon indicating copy to clipboard operation
bijection copied to clipboard

Add InjectionK and BijectionK

Open MansurAshraf opened this issue 8 years ago • 1 comments

Cats have InjectionK but their invert function returns Option[F[_]] which they are unwilling to change. It would nice to have InjectionK with invert defined as Try[F[_]] as we have for all our existing injections. While Option[F[_]] maybe more theoretically correct, I have found Try[F[_]] to be more useful as I usually want to do something with he exception when inversion fails!. We would also need FunctionK as well

MansurAshraf avatar Sep 07 '17 23:09 MansurAshraf

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.

johnynek avatar Sep 07 '17 23:09 johnynek