op =
=
Defined in
- 5.2 Precedence and associativity — Precedence and associativity
- 5.3 Overloading and user-defined operators — Overloading built-in operators — op declarations in impl
- 1.6 Operators and delimiters — + - * / % ** +% -% % +| -| | & | ^ ~ << >> && || !
- 5.7 Lambdas and closures — .field and .method(args) in argument position are shorthand for a lambda with one parameter.
- 3.6 Aliases, new types and refined types — distinct T creates a new nominal type with the representation of T.
Examples
impl Vec3 {
static op +(a: Vec3, b: Vec3) -> Vec3 => Vec3(a.x + b.x, a.y + b.y, a.z + b.z)
static op *(v: Vec3, k: f32) -> Vec3 => Vec3(v.x * k, v.y * k, v.z * k)
static op -(v: Vec3) -> Vec3 => v * -1.0
op [](i: usize) -> f32 { … } // read by index
var op [](i: usize) -> &var f32 { … } // write by index
op ()(t: f32) -> Vec3 { … } // call as a function
static op <=>(a: Vec3, b: Vec3) -> Ordering { … }
op as Vec4 => Vec4(x, y, z, 1.0)
}— 5.3 Overloading and user-defined operators
let inc = x => x + 1
let add = (a: i32, b: i32) => a + b
users.map(.name) // = u => u.name
users.filter(.isActive()) // = u => u.isActive()
retryWith(3) { fetch() } // a closure as the last argument
cluster.lock("k", ttl: LOCK_TTL) { migrate() }Related diagnostics
chained-comparison, not-callable, not-overloadable, operator-decl, range-not-iterable, invalid-char, refinement-violated