Task represents an asynchronous or effectful computation whose result may succeed or fail. It wraps IO[Try[A]], allowing evaluation errors to remain inside the computation until explicitly handled. section 15.3.2
Task supports several compositional error-handling operations:
- map sequences successful results while preserving failures. section 15.3.2
- attempt exposes the underlying Try value. section 15.3.2
- handleErrorWith sequences the error channel and can replace a failure with a fallback Task. section 15.3.2
Recovering from a failed conversion
Task("asdf".toInt) stores a NumberFormatException as a Failure. Mapping does not run its success function; handleErrorWith can instead return Task(0). section 15.3.2
