Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public protocol P {
- var foo: Int { get }
- }
- internal protocol Q {
- init(from: [String])
- }
- public struct S: P, Q {
- public var foo: Int = 0
- public init() {}
- internal init(from: [String]) {
- precondition(from.count > 0)
- self.foo = Int(from[0])!
- }
- }
- public class ProviderOfThings {
- public func map<T: P>(before: T) -> T {
- return T(from: [String(before.foo + 1)])
- }
- }
- public static func map<T: P>(before: T) -> T {
- return type(of: before as! Q).init(
- from: [String(before.foo + 1)]
- ) as! T
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement