Skip to content

Instantly share code, notes, and snippets.

@dam5s
Created November 3, 2020 18:05
Show Gist options
  • Save dam5s/2398759ce8deb46a3afdd1d34fc39ee8 to your computer and use it in GitHub Desktop.
Save dam5s/2398759ce8deb46a3afdd1d34fc39ee8 to your computer and use it in GitHub Desktop.
Limitations (?) to Swift extensions.
class Async<Wrapped> {
func map(function: @escaping (Wrapped) -> NewWrapped) -> Async<NewWrapped> {
// ...
}
// ...
}
typealias AsyncResult<Success, Failure> = Async<Result<Success, Failure>>
extension AsyncResult {
// The function below cannot be declared because there are no Success or Failure types in scope
func mapSuccess<NewSuccess>(function: @escaping (Success) -> NewSuccess) -> AsyncResult<NewSuccess, Failure> {
// ...
}
// ...
}
@BrianSemiglia
Copy link

BrianSemiglia commented Nov 3, 2020

You can constrain the function's generic New or the instance's generics Success, Failure or both.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment