Trait in prelude::ops auto-imported

Length

trait Length<T>
Source: compiler/src/builtin_docs/prelude/ops.hy

A size query: x.len().

Arrays, Vec, strings (UTF-8 bytes), tuples and records (fields) have a structural length and need no instance; fixed sizes fold at compile time. They meet a T: Length bound too, len reading that same length. Implement Length to give your own type a length.

Required methods#

NameDescription
lenReturns the length of value.

Examples#

use tests::assert;
class Team {
    pub names: Vec<string>,
}

impl Length for Team {
    pub fn len(Team t) -> int {
        return t.names.len();
    }
}

fn main() {
    let t = new Team(Vec::from(["ana", "bo"]));
    assert!(t.len() == 2);
}

See also#

  • Vec
  • Length::len
  • Add: The addition operator +.
  • Sub: The subtraction operator -.
  • Mul: The multiplication operator *.
  • Div: The division operator /.
  • Neg: The unary negation operator -x.
  • Rem: The remainder operator %.
↑ ↓ navigate ↵ open