Skip to main content
Version: 3.0.0-dev πŸ”¨

πŸ“‘ Glossary of Terms

Notation

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​

An Algebraic Data Type.

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​

If-and-only-if.

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​

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​

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.