DEV Community

Discussion on: Abstraction & Type-Safety using Singleton Variants

johnridesabike profile image
John Jackson

This is a great trick! There’s another cool way you can easily unbox values from variants:

let FirstName(nameString) = name;

that will assign nameString to the string inside name, just like in the fun example. I tend to prefer this syntax because it prints nicer with refmt, although it admittedly looks a little weird.

You can also do it with multiple variants:

let FirstName(nameString) | Nickname(nameString) = name;
rawtoast profile image
RawToast Author

I completely forgot about the first one... I actually use it a lot xD