<commit_before>Enums
=====

Like many other languages, enums in Bagel let you specify several different
values a variable can contain::

    enum class MeasuringSystem:
        Imperial
        Metric

Then we can declare functions which take one of these values, and use
:term:`pattern matching` to handle them::

    def distance_unit(system: MeasuringSystem) -> Text:
        match system:
            as Imperial:
                return "Feet"
            as Metric:
                return "Meters"

The Bagel compiler will make sure that you handle all possible cases, so if you
add a new value to ``MeasuringSystem`` without adding handling to
``distance_unit`` you will get a compilation error, tell you about the
unhandled case.

Unlike many programming languages, Bagel's enums can contain other values::

    enum class Distance:
        Inches(UInt)
        Feet(UInt)

Again, we can use pattern matching to handle these values, also unpacking the
value::

    def distance_in_inches(d: Distance) -> UInt:
        match d:
            as Inches(x):
                return x
            as Feet(x):
                return x * 12

Enum values are immutable, after creating one, it's not possible to change any
of the values inside of it.

You can make use of both of these features in a single enum. Also, when an enum
contains another value, it can optionally be given a label::

    enum class TalkSubmissionStatus:
        Accepted
        InReview
        Rejected(reason: Text)


    def talk_status_notice(status: TalkSubmissionStatus) -> Text:
        match status:
            as Accepted:
                return "Your talk was accepted"
            as InReview:
                return "Your talk is still being reviewed"
            as Rejected(reason):
                return reason
<commit_msg>Typo fixes and rephrases<commit_after>Enums
=====

Like many other languages, enums in Bagel let you specify several different
values a variable can contain::

    enum class MeasuringSystem:
        Imperial
        Metric

Then we can declare functions which take one of these values, and use
:term:`pattern matching` to handle them::

    def distance_unit(system: MeasuringSystem) -> Text:
        match system:
            as Imperial:
                return "Feet"
            as Metric:
                return "Meters"

The Bagel compiler will make sure that you handle all possible cases, so if you
add a new value to ``MeasuringSystem`` without adding handling to
``distance_unit`` you will get a compilation error, telling you about the
unhandled case.

Unlike many programming languages, Bagel's enums can contain other values::

    enum class Distance:
        Inches(UInt)
        Feet(UInt)

Again, we can use pattern matching to handle these, also unpacking the values::

    def distance_in_inches(d: Distance) -> UInt:
        match d:
            as Inches(x):
                return x
            as Feet(x):
                return x * 12

Enum values are immutable, after creating one, it's not possible to change any
of the values inside of it.

You can make use of both of these features in a single enum. When an enum
contains another value, it can optionally be given a label::

    enum class TalkSubmissionStatus:
        Accepted
        InReview
        Rejected(reason: Text)


    def talk_status_notice(status: TalkSubmissionStatus) -> Text:
        match status:
            as Accepted:
                return "Your talk was accepted"
            as InReview:
                return "Your talk is still being reviewed"
            as Rejected(reason):
                return reason

{'fraction_non_alphanumeric': 0.05426997245179063, 'fraction_numerical': 0.0011019283746556473, 'mean_word_length': 2.3496309963099633, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '4404170', 'n_tokens_mistral': 953, 'n_tokens_neox': 897, 'n_words': 433}