Swiftpack.co - Package - ellneal/swift-result

Result

A simple Result<Success, Failure: Swift.Error> while we wait for Swift 5.

Installation

SwiftPM

...
    dependencies: [
        .package(url: "https://github.com/ellneal/swift-result", from: "2.0.0"),
    ]
...

Carthage

github "ellneal/swift-result" ~> 2.0.0

Usage

enum CustomError: Swift.Error {
    case someError
}

let value: Result<String, CustomError> = .success("Value")
try {
    let string = try value.resolve()
    print(string) // prints "Value"
} catch {
    // won't throw
}

let error: Result<String, CustomError> = .failure(.someError)
try {
    let never = try value.resolve()
} catch let error {
    print(error) // prints CustomError.someError
}

EmptyResult

Empty result is useful when there's no corresponding value for a successful result.

let success: EmptyResult<CustomError> = .success

// syntactic sugar for let success: Result<Void, CustomError> = .success(())

InfallibleResult

An InfallibleResult<Success> can never be in error (Result<Success, Never>).

ErroneousResult

An ErroneousResult<Failure> can never have a value (Result<Never, Failure>).

Contributing

Setup

git clone git@github.com:ellneal/swift-promise.git
cd swift-promise
make generate-xcodeproj && open Result.xcodeproj

Github

link
Stars: 0
Help us keep the lights on

Dependencies

Used By

Total: 0

Releases

v2.0.0 - Jan 25, 2019

v1.1.2 - Jan 25, 2019

v1.1.1 - Jan 16, 2019

v1.1.0 - Jan 9, 2019

v1.0.1 - Jan 7, 2019