iyi

Standard library, 0.18.0

std/traits

Comparable, Num and Hashable over the prelude's scalars, and Hashable over the other keys a table takes: tuples, named tuples, arrays, nil and symbols.

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

The imports are what makes Hashable true rather than declared. hash_key forwards to the value's own hash, and the prelude defines hash for Int32, String and a handful more; every other integer's lives in std/int, both floats' in std/float, and a named tuple's in std/tuple. Importing neither number module, impl Hashable for Int16 forwarded to Object#hash — the type's id, one slot for every value of the type — so 1_i16.hash == 31337_i16.hash was true, and 1.5.hash == 31337.5.hash with it. A trait may not promise what the module implementing it has not loaded (SPEC.md II.8).

Each named, though std/float imports std/int itself: an integer's hash is not a thing to reach through a float, and a rule that holds only while somebody else's import survives is not held.

Comparabletrait

std/traitsiyi doc src/std/traits.iyi
pub trait Comparable
  def <(other : self) : Bool
  def <=(other : self) : Bool
  abstract def <=>(other : self) : Int32
  def ==(other : self) : Bool
  def >(other : self) : Bool
  def >=(other : self) : Bool
  def between?(min : self, max : self) : Bool
  def clamp(min : self, max : self) : self
  def clamp(range : Range) : self
end

Hashabletrait

std/traitsiyi doc src/std/traits.iyi
pub trait Hashable
  abstract def hash_key : Int32
end

Numtrait

std/traitsiyi doc src/std/traits.iyi
pub trait Num : ::Std::Traits::Comparable
  abstract def add(other : self) : self
  abstract def mul(other : self) : self
  abstract def self.one : self
  # Class-level requirements. `Enumerable#sum` and `#product` need an additive
  # and a multiplicative identity, and an identity belongs to the type, not to
  # any value of it — there is no element to ask when the collection is empty.
  abstract def self.zero : self
end

Comparable for Int32impl

std/traitsiyi doc src/std/traits.iyi
impl Comparable for Int32
  def <=>(other : self) : Int32
end

Num for Int32impl

std/traitsiyi doc src/std/traits.iyi
impl Num for Int32
  def self.one : self
  def add(other : self) : self
  def mul(other : self) : self
end

Hashable for Int32impl

std/traitsiyi doc src/std/traits.iyi
impl Hashable for Int32
  def hash_key : Int32
end

Comparable for Int64impl

std/traitsiyi doc src/std/traits.iyi
impl Comparable for Int64
  def <=>(other : self) : Int32
end

Num for Int64impl

std/traitsiyi doc src/std/traits.iyi
impl Num for Int64
  def self.one : self
  def add(other : self) : self
  def mul(other : self) : self
end

Hashable for Int64impl

std/traitsiyi doc src/std/traits.iyi
impl Hashable for Int64
  def hash_key : Int32
end

Comparable for UInt8impl

std/traitsiyi doc src/std/traits.iyi
impl Comparable for UInt8
  def <=>(other : self) : Int32
end

Num for UInt8impl

std/traitsiyi doc src/std/traits.iyi
impl Num for UInt8
  def self.one : self
  def add(other : self) : self
  def mul(other : self) : self
end

Hashable for UInt8impl

std/traitsiyi doc src/std/traits.iyi
impl Hashable for UInt8
  def hash_key : Int32
end

Comparable for UInt64impl

std/traitsiyi doc src/std/traits.iyi
impl Comparable for UInt64
  def <=>(other : self) : Int32
end

Num for UInt64impl

std/traitsiyi doc src/std/traits.iyi
impl Num for UInt64
  def self.one : self
  def add(other : self) : self
  def mul(other : self) : self
end

Hashable for UInt64impl

std/traitsiyi doc src/std/traits.iyi
impl Hashable for UInt64
  def hash_key : Int32
end

Comparable for Float64impl

std/traitsiyi doc src/std/traits.iyi
impl Comparable for Float64
  def <=>(other : self) : Int32
end

Num for Float64impl

std/traitsiyi doc src/std/traits.iyi
impl Num for Float64
  def self.one : self
  def add(other : self) : self
  def mul(other : self) : self
end

Hashable for Float64impl

std/traitsiyi doc src/std/traits.iyi
impl Hashable for Float64
  def hash_key : Int32
end

Comparable for Stringimpl

std/traitsiyi doc src/std/traits.iyi
impl Comparable for String
  # `<=>` is not a method the prelude's `String` has, so this was a call
  # nobody could make; `<` and `==` are what it does have.
  def <=>(other : self) : Int32
end

Hashable for Stringimpl

std/traitsiyi doc src/std/traits.iyi
impl Hashable for String
  def hash_key : Int32
end

Comparable for Charimpl

std/traitsiyi doc src/std/traits.iyi
impl Comparable for Char
  def <=>(other : self) : Int32
end

Hashable for Charimpl

std/traitsiyi doc src/std/traits.iyi
impl Hashable for Char
  def hash_key : Int32
end

Hashable for Boolimpl

std/traitsiyi doc src/std/traits.iyi
impl Hashable for Bool
  def hash_key : Int32
end

Comparable for Int8impl

std/traitsiyi doc src/std/traits.iyi
impl Comparable for Int8
  def <=>(other : self) : Int32
end

Num for Int8impl

std/traitsiyi doc src/std/traits.iyi
impl Num for Int8
  def self.zero : self
  def self.one : self
  def add(other : self) : self
  def mul(other : self) : self
end

Hashable for Int8impl

std/traitsiyi doc src/std/traits.iyi
impl Hashable for Int8
  def hash_key : Int32
end

Comparable for Int16impl

std/traitsiyi doc src/std/traits.iyi
impl Comparable for Int16
  def <=>(other : self) : Int32
end

Num for Int16impl

std/traitsiyi doc src/std/traits.iyi
impl Num for Int16
  def self.zero : self
  def self.one : self
  def add(other : self) : self
  def mul(other : self) : self
end

Hashable for Int16impl

std/traitsiyi doc src/std/traits.iyi
impl Hashable for Int16
  def hash_key : Int32
end

Comparable for UInt16impl

std/traitsiyi doc src/std/traits.iyi
impl Comparable for UInt16
  def <=>(other : self) : Int32
end

Num for UInt16impl

std/traitsiyi doc src/std/traits.iyi
impl Num for UInt16
  def self.zero : self
  def self.one : self
  def add(other : self) : self
  def mul(other : self) : self
end

Hashable for UInt16impl

std/traitsiyi doc src/std/traits.iyi
impl Hashable for UInt16
  def hash_key : Int32
end

Comparable for UInt32impl

std/traitsiyi doc src/std/traits.iyi
impl Comparable for UInt32
  def <=>(other : self) : Int32
end

Num for UInt32impl

std/traitsiyi doc src/std/traits.iyi
impl Num for UInt32
  def self.zero : self
  def self.one : self
  def add(other : self) : self
  def mul(other : self) : self
end

Hashable for UInt32impl

std/traitsiyi doc src/std/traits.iyi
impl Hashable for UInt32
  def hash_key : Int32
end

Comparable for Int128impl

std/traitsiyi doc src/std/traits.iyi
impl Comparable for Int128
  def <=>(other : self) : Int32
end

Num for Int128impl

std/traitsiyi doc src/std/traits.iyi
impl Num for Int128
  def self.zero : self
  def self.one : self
  def add(other : self) : self
  def mul(other : self) : self
end

Hashable for Int128impl

std/traitsiyi doc src/std/traits.iyi
impl Hashable for Int128
  def hash_key : Int32
end

Comparable for UInt128impl

std/traitsiyi doc src/std/traits.iyi
impl Comparable for UInt128
  def <=>(other : self) : Int32
end

Num for UInt128impl

std/traitsiyi doc src/std/traits.iyi
impl Num for UInt128
  def self.zero : self
  def self.one : self
  def add(other : self) : self
  def mul(other : self) : self
end

Hashable for UInt128impl

std/traitsiyi doc src/std/traits.iyi
impl Hashable for UInt128
  def hash_key : Int32
end

Comparable for Float32impl

std/traitsiyi doc src/std/traits.iyi
impl Comparable for Float32
  def <=>(other : self) : Int32
end

Num for Float32impl

std/traitsiyi doc src/std/traits.iyi
impl Num for Float32
  def self.zero : self
  def self.one : self
  def add(other : self) : self
  def mul(other : self) : self
end

Hashable for Float32impl

std/traitsiyi doc src/std/traits.iyi
impl Hashable for Float32
  def hash_key : Int32
end

Hashable for Tuple(*T) forall Timpl

std/traitsiyi doc src/std/traits.iyi
impl Hashable for Tuple(*T) forall T
  def hash_key : Int32
end

Hashable for NamedTuple(T) forall Timpl

std/traitsiyi doc src/std/traits.iyi
impl Hashable for NamedTuple(T) forall T
  def hash_key : Int32
end

Hashable for Array(T) forall Timpl

std/traitsiyi doc src/std/traits.iyi
impl Hashable for Array(T) forall T
  def hash_key : Int32
end

Hashable for Nilimpl

std/traitsiyi doc src/std/traits.iyi
impl Hashable for Nil
  def hash_key : Int32
end

Hashable for Symbolimpl

std/traitsiyi doc src/std/traits.iyi
impl Hashable for Symbol
  def hash_key : Int32
end