<commit_before><commit_msg>https://github.com/AndreyAttr/Evo/issues/48 discriminated enums(wrap enum type into wrapper with discriminant property and then use that property to distinguish what kind of enum to use - aggregate all the logic needed in one function/method)<commit_after>// Discriminated Unions(tagged unions, algebraic data types)
// Combination of string literal types, union types, type guards and type aliases

enum Enum1{id, name, description};
enum Enum2{age, address};
enum Enum3{prefferences, options};
//Non hierarchical(without inheritance) - discriminated interfaces:
interface DiscriminatedEnum1{
    kind: "enum1",      //discriminant property
    value: Enum1
}
interface DiscriminatedEnum2{
    kind: "enum2",
    value: Enum2
}
interface DiscriminatedEnum3{
    kind: "enum3",
    value: Enum3
}
type Enums = Enum1 | Enum2 | Enum3;
type DiscriminatedEnums = DiscriminatedEnum1 | DiscriminatedEnum2 | DiscriminatedEnum3;     //union & aliasing

/*
 https://www.typescriptlang.org/docs/handbook/advanced-types.html - Exhaustiveness checking
* Here, assertNever checks that s is of type never — the type that’s left after all other cases have been removed.
* If you forget a case, then s will have a real type and you will get a type error.
* This method requires you to define an extra function, but it’s much more obvious when you forget it.
* */
function assertNever(enums: never):never{
    throw new Error(`Unexisted enum type: ${enums}`);
}

function getEnumValue(enums: DiscriminatedEnums): Enums{
    switch (enums.kind){
        case "enum1": return enums.value;
        case "enum2": return enums.value;
        case "enum3": return enums.value;
        default: return assertNever(enums);
    }
}
{'fraction_non_alphanumeric': 0.08833718244803695, 'fraction_numerical': 0.013279445727482679, 'mean_word_length': 4.251515151515152, 'pattern_counts': {'":': 3, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2360335', 'n_tokens_mistral': 504, 'n_tokens_neox': 488, 'n_words': 187}