Skip to content

Instantly share code, notes, and snippets.

@dmcyk
Created March 17, 2018 21:20
Show Gist options
  • Save dmcyk/279b45d158aee8b20bec72ef0dfd3eb3 to your computer and use it in GitHub Desktop.
Save dmcyk/279b45d158aee8b20bec72ef0dfd3eb3 to your computer and use it in GitHub Desktop.
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