Proposal: lifting between monad transformers, simple effect types and raw types
Nobody has claimed this yet.
- Dominant language
- Scala
- Stars
- 5.5k
- Forks
- 1.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 5
Description
In practice, I often encounter situations when I need to lift F[_] to EitherT or OptionT. For EitherT, the only current option is EitherT.right[E](foo: F[A]): EitherT[F, E, A]. Compare that to A-F[A] interop or OptionT-EitherT interop:
(a: A).pure[F]: F[A]
(o: OptionT[F, A]).toRight(error: E): EitherT[F, E, A]
(e: EitherT[F, E, A]).toOption: OptionT[F, A]
Similarly, I think it is a good idea to have rich wrappers such as to allow:
(fa: F[A]).toRight[E]: EitherT[F, E, A]
(fa: F[A]).toLeft[B]: EitherT[F, A, B]
(fe: F[Either[E, A]]).lift: EitherT[F, E, A]
(fo: F[Option[A]]).lift: OptionT[F, A]
The EitherT.right(foo: F[A]) is a bit cumbersome because:
- There's a redundancy of information: in general,
rightuniquely impliesEitherTwhen used onF[A] - You could solve the above redundancy by importing
EitherT.{right, ...}– however, there is a bunch of conversion methods defined on EitherT, and the need to manage the imports might introduce some mental overhead. Ideally, I'd like to be able to just import Cats once (e.g. currently I am usingimport cats._, cats.implicits._, cats.data._, cats.effect._) and forget about it. - There are extra parentheses:
right[E](fa)vsfa.toRight. Parentheses clutter code. - The syntax is not uniform with that of
A: if I can doa.pure[EitherT[...]], I'd also like to be able to dofa.toRight[E].
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the existing EitherT.right entry point and the OptionT/EitherT conversion methods described in the proposal. Compare their syntax and semantics with the requested F[A].toRight, F[A].toLeft, and F[Either] or F[Option] lifting APIs; done requires an agreed scope and corresponding implementation and tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- scala
- Domain
- backend-api-design
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100