Created
March 17, 2018 21:20
-
-
Save dmcyk/279b45d158aee8b20bec72ef0dfd3eb3 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
public final class FancyClass { | |
public enum FancyEnum { | |
case a | |
case b | |
} | |
public let fancy: FancyEnum | |
private let ptrCall: (Double) -> Double | |
public init(_ fancy: FancyEnum) { | |
self.fancy = fancy | |
switch fancy { | |
case .a: ptrCall = FancyClass.aCall | |
case .b: ptrCall = FancyClass.bCall | |
} | |
} | |
private static func aCall(_ a: Double) -> Double { return a } | |
private static func bCall(_ b: Double) -> Double { return b * 2 } | |
public func makeCheckedCall(_ a: Double) -> Double { | |
switch fancy { | |
case .a: return FancyClass.aCall(a) | |
case .b: return FancyClass.bCall(a) | |
} | |
} | |
public func makePtrCall(_ a: Double) -> Double { | |
return ptrCall(a) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment