New Typestate pattern in Swift

This article will teach you 3 ideas:

  1. Typestate Design Pattern.
  2. The power of generic constraints.
  3. Swift 5.9 new Noncopyable types and consuming functions.

I think all these things could be worth exploring for Crystal at some point (at least it had crossed my mind before that something like this might be valuable…).

3 Likes

If we were to port those snippets to Crystal, I don’t think I understand why the states need to be specializations of a single generic, rather than a simple union

Yeah, this could be a good alternative. At least for this example.
Generic specializations could certainly be useful for other things.