Created
June 15, 2017 06:28
-
-
Save lukesutton/0685aa41f3507823f72b83ec198efc57 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
protocol Cancellable {} | |
protocol Billable {} | |
struct Initial: Cancellable {} | |
struct Placed: Cancellable, Billable {} | |
struct Billed: Cancellable {} | |
struct Packed: Cancellable, Billable {} | |
struct Shipped {} | |
struct LostInTransit {} | |
struct DamagedInTransit {} | |
struct Cancelled {} | |
struct Order<T> { | |
} | |
extension Order where T == Initial { | |
var place: Order<Placed> { | |
return Order<Placed>() | |
} | |
} | |
extension Order where T: Cancellable { | |
var cancel: Order<Cancelled> { | |
return Order<Cancelled>() | |
} | |
} | |
extension Order where T: Billable { | |
var bill: Order<Billed> { | |
return Order<Billed>() | |
} | |
} | |
extension Order where T == Billed { | |
var pack: Order<Packed> { | |
return Order<Packed>() | |
} | |
} | |
extension Order where T == Packed { | |
var ship: Order<Shipped> { | |
return Order<Shipped>() | |
} | |
} | |
let o1 = Order<Initial>() | |
let o2 = o1.place.bill.pack.ship | |
print(o2) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment