Success

Inherits from: Result ← Object

A Result representing a successful outcome wrapping a value.

Create with Success with: value or Result success: value. The wrapped value is accessible via value. Chaining methods (then:, map:, flatMap:) pass the value through the block; branching methods (ifSuccess:, ifFailure:, onSuccess:onFailure:) evaluate only the success path.

Test
(Success with: 42) value >>> 42
(Success with: 42) isSuccess >>> true
(Success with: 42) isFailure >>> false
(Success with: 42) error >>> nil
(Success with: 'hello') value >>> 'hello'
Example
"Transform and branch on a successful result"
(Success with: 10)
    map: [:v | v * 2]
    ifSuccess: [:v | 'Result is: ', v printString]

Class Methods

primitives

class with:

Instance Methods

primitives

flatMap:
ifFailure:
ifSuccess:
map:
onSuccess:onFailure:
primValue
then:

uncategorized

error

Return nil -- a Success carries no error.

Test
(Success with: 42) error >>> nil
isFailure

Answer false -- the receiver is not a failure.

Test
(Success with: 1) isFailure >>> false
isSuccess

Answer true -- the receiver represents a successful outcome.

Test
(Success with: 1) isSuccess >>> true
printString

Return a human-readable representation including the wrapped value.

Test
(Success with: 42) printString >>> 'Success(42)'
(Success with: 'hi') printString >>> 'Success(''hi'')'
value

Return the wrapped success value.

Test
(Success with: 42) value >>> 42
(Success with: 'ok') value >>> 'ok'