Skip to content

Instantly share code, notes, and snippets.

@cedricbahirwe
Last active May 3, 2023 17:35
Show Gist options
  • Save cedricbahirwe/6eefc267273a8ad0f081e3c73eb54dd4 to your computer and use it in GitHub Desktop.
Save cedricbahirwe/6eefc267273a8ad0f081e3c73eb54dd4 to your computer and use it in GitHub Desktop.
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