Last active
May 2, 2020 11:08
-
-
Save kateinoigakukun/9d4c882822a97955f617b45fac5caf6c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func id<T>(_ v: T) -> T { v } | |
func produceError() throws {} | |
// throws version | |
func f(_ a: () throws -> Void) rethrows { try a() } | |
f { } | |
try f { try produceError() } | |
try id(f)({ }) // Never `throw` but need `try` 😢 | |
try id(f)({ try produceError() }) | |
// Result version | |
func g<E>(_ a: () -> Result<Void, E>) -> Result<Void, E> { a() } | |
g { Result<Void, Never>.success(()) } // Result<Void, Never> | |
g { Result { try produceError() } } // Result<Void, Error> | |
id(g)({ Result<Void, Never>.success(()) }) // Result<Void, Never> 😎 | |
id(g)({ Result { try produceError() } }) // Result<Void, Error> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment