Last active
May 3, 2023 17:35
-
-
Save cedricbahirwe/6eefc267273a8ad0f081e3c73eb54dd4 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 | |
// The life of a developer using Phantom Types | |
enum Eating {} | |
enum Coding {} | |
enum Sleeping {} | |
struct Transition<From, To> { } | |
struct Life<State> { | |
func transition<To>(with transition: Transition<State, To>) -> Life<To> { | |
.init() | |
} | |
} | |
let start = Transition<Eating, Coding>() | |
let process = Transition<Coding, Sleeping>() | |
let reset = Transition<Sleeping, Eating>() | |
let l1 = Life<Eating>() | |
let l2 = l1.transition(with: start) | |
let l3 = l2.transition(with: process) | |
let l4 = l3.transition(with: reset) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment