Package -

ResultK

ResultK provides Result suitable to Swift's untyped throws. PromiseK's Result does not have the second type parameter to specify the error type unlike antitypical/Result.

let a: Result<Int> = Result { try primeOrThrow(2) }
switch a {
case let .success(value):
    print(value)
case let .failure(error):
    print(error)
}

Result is a monad. map and flatMap are available for Result.

let b: Result<Int> = Result(3)
let sum: Result<Int> = a.flatMap { a in b.map { b in a + b } } // Result(5)

Installation

Swift Package Manager

Add the following to dependencies in your Package.swift.

.package(
    url: "https://github.com/koher/ResultK.git",
    from: "0.2.0-alpha"
)

License

The MIT License

Github

link
Stars:

Advertisement