One note to add to @yawaramin’s answer, the as a can be also useful for performance.
When you write this: | Reloading(a) => Reloading(a) Then you’re deconstructing the variant and then constructing it again.
But when you write it like this: | Reloading(_) as a => a Then you just reuse the existing value, so you save a small amount of performance.
But for variant constructors without arguments, such as Loading, then this probably doesn’t actually save anything (since Loading just compiles to an integer). I assume whoever wrote that code did it mainly for consistency.
You can also combine as a with nested | patterns, so this would be an even shorter way to write that function:
let toBusy = v =>
switch v {
| Init => Loading
| (Loading | Reloading(_)) as a => a
| Complete(a) => Reloading(a)
}