Link Search Menu Expand Document

Enums

Table of contents

  1. Enums
    1. Enum.values()

Enums

Enums are a collection of constants which can be accessed via a name rather than an index to document intent. Unlike other languages, enums in Dictu do not generate a value based on the previous entry, instead if no value is assigned it will be given it’s position within the enum, 0-based, as a value.

enum MyEnum {
    a, // 0
    b, // 1
    c  // 2
}

print(MyEnum.a); // 0

enum Test {
    a = 10, // 10
    b,      // 1
    c       // 2
}

print(Test.a); // 10

Enums in Dictu also do not care about the value being stored within the enum, so if you wanted to create a heterogeneous enum, Dictu will not stop you.

enum HeterogeneousEnum {
    a = 0,
    b = "string",
    c = def () => 10
}

Enum.values()

To get all values within an Enum you can use the .values() method. This will return a dictionary.

enum Test {
    a = 10, // 10
    b,      // 1
    c       // 2
}

print(Test.values()); // {"c": 2, "a": 10, "b": 1}

This site uses Just The Docs, with modifications.