Emojicode Documentation 1.0 beta 2

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