Add attemptT variant accepting a partial function
Open
Nobody has claimed this yet.
- Dominant language
- Scala
- Stars
- 5.5k
- Forks
- 1.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 5
Description
I sometimes find myself trying to recover some Throwables as Left in EitherT. It gets noisy:
val doSomething: IO[Foo] = ???
val doSomething0: EitherT[IO, MyError, Foo] =
EitherT(
doSomething.map(_.asRight).recover {
case e: IOException => MyError(e).asLeft
case e: SQLException => MyError(e).asLeft
}
)
It would be nice to have a combinator that would encapsulate this pattern:
doSomething.attemptPartialT {
case e: IOException => MyError(e)
case e: SQLException => MyError(e)
}
We can also have an Either version of it, as a more general version of attemptNarrow.
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 locating the existing attemptNarrow implementation and the EitherT APIs involved in the example. Compare how the proposed partial-function forms should relate to those entry points, then add coverage for the IOException and SQLException cases and verify that unmatched Throwables retain the expected behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- scala
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100