All operator in Hades can be overloaded. The syntax for this is similar to overloading an inherited function. Operator overloading in Hades always assumes a right operation so the base for the operation is always the parameter on the left.

with console from std:ioâ€‹class Vectorvar x = 0var y = 0var z = 0func Vector(x,y,z)this->x = xthis->y = ythis->z = zendfunc! toString()put "{},{},{}"->format(x,y,z)endfunc! op+(v)if(v is int)put Vector(x+v,y+v,z+v)else if(v is Vector)put Vector(x + v->x, y + v->y, z + v->z)endput nullendendâ€‹var v1 = Vector(1,2,3)var v2 = Vector(4,5,6)â€‹var v3 = v1 + v2 //overloaded operator is called on v1console->out(v3) //outputs: 5,7,9

One special case of operator overloading is when you want to overload the index operator `[]`

.

There are two functions that can be overwritten:

reading from an index:

`index(args indices)`

writing to an index:

`index(args indicies, newValue)`

class MyWayCoolerMapImplementationprivate let map = Map()func! index(args indices)if (indices->length is 1)let index = indices[0]put map->get(index)endraise ArgumentError()endfunc! index(args indices, newValue)if (indices->length is 1)let index = indices[0]map->put(index, newValue)endraise ArgumentError()endend