Failure

Inherits from: Result ← Object

A Result representing a failed outcome wrapping an error reason.

Create with Failure with: reason or Result failure: reason. The error is accessible via error; value always returns nil. Chaining methods (then:, map:, flatMap:) propagate the failure without evaluating the block; branching methods (ifSuccess:, ifFailure:, onSuccess:onFailure:) evaluate only the failure path.

Test
(Failure with: 'oops') error >>> 'oops'
(Failure with: 'oops') isFailure >>> true
(Failure with: 'oops') isSuccess >>> false
(Failure with: 'oops') value >>> nil
Example
"Failures propagate through chains untouched"
(Failure with: 'bad input')
    map: [:v | v * 2]
    then: [:v | Success with: v + 1]

Class Methods

primitives

class reason:
class with:

Instance Methods

primitives

flatMap:
ifFailure:
ifSuccess:
map:
onSuccess:onFailure:
primError
reason
then:

uncategorized

error

Return the wrapped error reason.

Test
(Failure with: 'oops') error >>> 'oops'
(Failure with: 404) error >>> 404
isFailure

Answer true -- the receiver represents a failed outcome.

Test
(Failure with: 'err') isFailure >>> true
isSuccess

Answer false -- the receiver is not a success.

Test
(Failure with: 'err') isSuccess >>> false
printString

Return a human-readable representation including the error reason.

Test
(Failure with: 'oops') printString >>> 'Failure(''oops'')'
(Failure with: 404) printString >>> 'Failure(404)'
value

Return nil -- a Failure carries no success value.

Test
(Failure with: 'err') value >>> nil