enum-class: 'enum' class

Description Generic Enums Numeric Enums How enums differ from lists See Also

Description

The enum class is inspired by enumerated types in other languages, and draws much of its functionality from the primitive list class.

Generally, enums are more restrictive than lists, with the intent of promoting self-documenting code. They do not allow duplicate values or names, nor do they allow enum values to be changed later.

In essence, an enum can be thought of as a dictionary of values, which can be referenced later down the road with the assurance that the related value will never change.

The enum class is the parent of numeric and generic enums, and will always exist alongside one of the child classes. Which child class an enum will inherit is (generally) decided at run time.

See the pkgdown site for more information.

Generic Enums

Generic enums have:

Numeric Enums

Numeric enums have:

Implicit values are created when a name is passed to the enum constructor without a value associated with it. The constructor will then assign the name a value, which is either:

How enums differ from lists

List Enum
Primitive x
Static x
Allow duplicate names x
Allow duplicate values x
Allow values without names x
Implicit definition x ☑(Numeric enums)

See Also

enum(), as_enum(), print.enum()


ElianHugh/enumr documentation built on Dec. 17, 2021, 6:25 p.m.