π Glossary of Terms
I will use a monospaced name match()
when referring to the concrete types and values.
When speaking generally, I will refer to matching or the match functions, when describing match()
/matcher()
/prematch()
.
ADTβ
Algebraic Data Typeβ
Another name for a variant type.
Composabilityβ
Long story short, two things are composable if they can interact and perform their intended functionality without needing to be aware of each other or performing special handling.
Discriminantβ
TypeScript discriminated unions require at least one property to be shared among all forms with a unique string literal type registered to each form. This property (and more specifically it's key) is the discriminantβthe value used to discriminate between the options.
Domainβ
TODO: Steal this from the intro of the previous version.
Exhaustiveβ
The term "exhaustive" refers to some control flow statement where every branch is handled. Variant's match functions are exhaustive until instructed otherwise.
Expressionβ
An expression, in contrast to a statement is a section of code that returns a value and so can be used inline within other expressions or statements.
Iffβ
Matchβ
match()
- match a variant as an expression.matcher()
- match a variant in a builder pattern.prematch()
- match against a type of variant ahead-of-time.
An operation resembling a switch statement that can be performed on some instance of a variant. Matching in general refers to processing an instance of a variant by providing instructions on how to respond to each potential variation. There are several match functions available depending on your needs and aesthetic preferences.
Modelβ
Model is a bit of an overloaded term, but generally speaking refers to the abstract representation of your domain concerns. In code, it generally refers to the interfaces and types you use in your core logic.
Tagβ
Discriminated unions are also called "Tagged Unions" referring to each of the shapes being labeled or tagged distinctly. The "tag" of the dog form of Animal would be "dog".
TypeScriptβ
The language we all know and love. TypeScript is a statically typed layer on top of JavaScript, possibly the most widespread cross-platform language and runtime in the world.
Variant 3.0 introduces scoped variants which leverage TypeScript 4.1+
's template literal features. As such, TypeScript 4.1+
is required.
Variantβ
variant()
- create a new variant.
A variant is a uniquely powerful datatype. Like the traditional enum, a variant is capable of representing some state in different forms. Unlike the traditional enum, each form of a variant can maintain its own distinct properties.
Variants are also known as algebraic data types in the functional world or discriminated unions in the TypeScript world. Rust programmers may have found the contrast between variants and enums confusing. Rust's "enums" are proper variants, but this is not the case in most languages.
Variationβ
variation()
- create a new variant.
One of the potentially many forms of a variant. This is sometimes referred to as the form or the shape of the variant. If Animal is a variant, then cat is one variation.