Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add method to perform natural transformation of underlying Monad in Monad Transformers #1724

Closed
LukaJCB opened this issue Jun 9, 2017 · 4 comments

Comments

@LukaJCB
Copy link
Member

LukaJCB commented Jun 9, 2017

I've found myself in this position quite often and I think it might be very useful to be able to change the underlying Monad of a Monad Transformer.
For example in OptionT:

final case class OptionT[F[_], A](value: F[Option[A]]) {
  ...
  def transformF(fn: F ~> G): OptionT[G, A] = OptionT(fn(value))
  ...
}

We could add this to all Monad Transformers currently in cats, i.e.

  • OptionT
  • EitherT
  • StateT
  • WriterT
  • Kleisli

The name is debatable, other suggestions one might come up with are: mapF, mapK, or just transform.

Edit: Just realized Kleisli already has a method that does exactly this called transform so we should probably stick to that.

@LukaJCB
Copy link
Member Author

LukaJCB commented Jun 9, 2017

There also seems to be #1644 which adds a transformF function that also does the same thing to EitherT. I suggest we find a common name for this function (with the precedent of transform already available in Kleisli)

Edit: I see now, that EitherT already has a function called transform, so we might need to find a different solution. This makes it very difficult to find a common name.

We could either duplicate the function with the common name in Kleisli or EitherT or choose to break backwards compatibility. Personally, right now, I think I'd go for the former

@kailuowang
Copy link
Contributor

This might be calling a higher order Functor, mentioned in #1644

@kailuowang
Copy link
Contributor

also related, @edmundnoble has a HFunctor like type class in cats-mtl
https://gitter.im/typelevel/cats-dev?at=593b10d86462d8493cf8d3c4

@edmundnoble
Copy link
Contributor

This seems to be an exact duplicate of #1713.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants