iyi

Standard library, 0.18.0

std/enum

iyi: the rest of Enum, added to the prelude's.

import std/enum to use it. Source: src/std/enum.iyi at v0.18.0.

The prelude gives every enum its value, its name, == and the ordering, includes?, | and &, values/names, and the two questions that answer nil: parse? and from_value?. This module adds what is left: the conversions the value itself has (to_i, to_i32, to_i64, to_u8, to_u64, to_f64), member arithmetic (+/- an integer, ^ a member), <=>, clone, the io spellings of to_s/inspect, each, valid?, and the panicking halves of the two questions: from_value and parse, which refuse with the value or the name they were given.

A @[Flags] enum is treated the way the prelude treats it. each walks the members values lists — not None and All, which the compiler added. valid? answers what from_value? answers: a member, or zero (None); a combination of bits is not a member, and All is not one either. Whether a combination holds a bit is includes?'s question.

There is no ~: the prelude gives integers no complement, so an enum has none to build on.

Enumstruct, reopened

std/enumiyi doc src/std/enum.iyi
struct ::Enum
  # The member `other` places after this one; may name no member.
  def +(other : Int) : self
  # The member `other` places before this one; may name no member.
  def -(other : Int) : self
  # -1, 0 or 1 by value.
  def <=>(other : self) : Int32
  # The bits in exactly one of the two.
  def ^(other : self) : self
  def clone : self
  # Every member in the order written, as `values` lists them: for a flags
  # enum, without `None` and `All`.
  def self.each(& : (self -> Nil)) : Nil
  # The member numbered `val`; panics naming the value where no member is.
  def self.from_value(val : Int) : self
  def inspect(io : IyiIO) : Nil
  # The member named `string`, compared the lenient way `parse?` compares;
  # panics naming the text where no member is.
  def self.parse(string : String) : self
  def to_f64 : Float64
  def to_i : Int32
  def to_i32 : Int32
  def to_i64 : Int64
  def to_s(io : IyiIO) : Nil
  def to_u64 : UInt64
  def to_u8 : UInt8
  # Whether `val` is a member: what `from_value?` answers, as a Bool. For a
  # flags enum that is a single member or `None`; a combination and `All`
  # are not members.
  def self.valid?(val : self) : Bool
end