Create your own enum
Here is how to create your own enum.
Define Opt<T>
enum variants using type
At first, you need to define variant and containing value using type
. Each variant is represented by [variant-name]: [containing-value-type]
.
Create enum class using Enum
base class
Next, create the enum class using Enum
base class.
To create enum instance:
Create Some(T)
and None()
static methods
To generate Opt<T>
with Some(T)
or None()
as in Rust:
To create enum instance:
Add type-guard methods
To add isOk()
and isNone()
type-guard methods using EnumNarrowed
:
Now takeVariantValue()
returns value type is narrowed down by isSome()
and isNone()
.