运算符重载

import std.collection.*

main() {
    let a = List([1, 2, 3, 4, 5])
    a[-3] = 12
    a[-2] |> println
    a |> println
    "size: ${a.size}" |> println
}

class List<T> <: ToString where T <: ToString {
    public List(let v: ArrayList<T>) {}

    public init(a: Array<T>) {
        this.v = ArrayList<T>(a)
    }

    operator func [](idx: Int64): T {
        match {
            case idx > this.size => return this.v[this.size]
            case idx < 0 && -idx <= this.size => return this.v[this.size + idx]
            case -idx > this.size => return this.v[0]
            case _ => return this.v[idx]
        }
    }

    operator func [](idx: Int64, value!: T): Unit {
        match {
            case idx > this.size => this.v.add(value)
            case idx < 0 && -idx <= this.size => this.v[this.size + idx] = value
            case -idx > this.size => this.v[0] = value
            case _ => this.v[idx] = value
        }
    }

    public func toString(): String {
        return this.v.toString()
    }

    prop size: Int64 {
        get() {
            this.v.size
        }
    }
}