ResultK provides Result suitable to Swift’s untyped throws. ResultK‘s Result type 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.
ResultK
ResultK provides
Resultsuitable to Swift’s untypedthrows. ResultK‘sResulttype does not have the second type parameter to specify the error type unlike antitypical/Result.Resultis a monad.mapandflatMapare available forResult.Installation
Swift Package Manager
Add the following to
dependenciesin your Package.swift.Carthage
License
The MIT License