Emojicode Documentation 0.8
Guides Language Reference Package Index

Enumerations

Enumerations are a special kind of value type that represent a set of options from which one can be chosen.

Defining an Enumeration

The syntax to define an enumeration is:

enum ⟢ πŸ¦ƒ type-identifier type-body
enum-value ⟢ πŸ”˜ emoji-id

For example:

πŸ¦ƒ ⏰ πŸ‡
  πŸ”˜πŸ₯“
  πŸ”˜πŸ₯ž
  πŸ”˜πŸ₯
πŸ‰

In this example, an enumeration that named ⏰ is defined which offers the values πŸ₯“, πŸ₯ž and πŸ₯.

Instantiating an Enumeration

Every enumeration automatically provides intializers for all its options, named after the option the instance will represent. Like any value type, enumerations are instantiated with πŸ†•:

πŸ†•β°πŸ₯žβ—️

Enumerations cannot have custom initializers.

Methods

In the manner of any other value types, enumerations can have methods. The following examples shows an enumeration which provides a method that returns a textual description of the chosen value:

πŸ¦ƒ ⏰ πŸ‡
  πŸ”˜πŸ₯“
  πŸ”˜πŸ₯ž
  πŸ”˜πŸ₯

  ❗️ πŸ”‘ ➑️ πŸ”‘ πŸ‡
    β†ͺ️ πŸ• πŸ™Œ πŸ†•β°πŸ₯ ❗️ πŸ‡
      ↩️ πŸ”€CroissantπŸ”€
    πŸ‰
    β†ͺ️ πŸ• πŸ™Œ πŸ†•β°πŸ₯ž ❗️ πŸ‡
      ↩️ πŸ”€PancakesπŸ”€
    πŸ‰
    β†ͺ️ πŸ• πŸ™Œ πŸ†•β°πŸ₯“ ❗️ πŸ‡
      ↩️ πŸ”€BaconπŸ”€
    πŸ‰
    ↩️ πŸ”€πŸ”€
  πŸ‰
πŸ‰

Comparing Enums

πŸ™Œ can be used to compare whether two enum instances are equal:

πŸ†•β°πŸ₯“❗️ ➑️ a
πŸ†•β°πŸ₯“❗️ ➑️ b
β†ͺ️ a πŸ™Œ b πŸ‡
  πŸ˜€ πŸ”€EqualπŸ”€β—οΈ
πŸ‰
← Previous Next Up: β€œTypes and Namespaces” β†’
Something not quite right? Improve this page