Skip to content
Discussion options

You must be logged in to vote

👋 I would go with those solutions:

import kyo.*

trait mapErrorOnThrowable[A, S]:

  val computation: A < (Abort[Throwable] & S)

  // doesn't handle the Panic
  val usingCombinators_1: A < (Abort[String] & S) = computation.mapAbort(e => e.getMessage)

  val usingCombinators_2: A < (Abort[String] & S) =
    computation.result.map:
      case Result.Success(value) => value
      case Result.Error(e)       => Abort.fail(e.getMessage)

  // Handling
  val usingAborts_1: A < (Abort[String] & S) =
    Abort.recoverError[Throwable](e => Abort.fail(e.failureOrPanic.getMessage))(computation)

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@DGolubets
Comment options

@ahoy-jon
Comment options

Answer selected by DGolubets
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants