Created
August 18, 2020 21:51
-
-
Save rydermackay/148c2441d928e1c0c25813cfae4146d5 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
import Foundation | |
struct Box<Value> { | |
let value: Value | |
} | |
extension Box { | |
// 1. | |
func map<T>(_ f: @escaping (Value) -> T) -> Box<T> { | |
return Box<T>(value: f(value)) | |
} | |
// 2. | |
func map<T>(_ value: T) -> Box<T> { | |
return map { _ in value } | |
} | |
// 3. | |
func map<T>(_ keyPath: KeyPath<Value, T>) -> Box<T> { | |
return map { $0[keyPath: keyPath] } | |
} | |
} | |
func test(input: Box<Void>) -> Box<String> { | |
// Xcode 12b4: output is Box<String> (overload #1) | |
// Xcode 12b5: output is Box<() -> String> (overload #2, but only when both #2 AND #3 exist!!) | |
let output = input.map { "foo" } | |
return output | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment