#Import "<std>"
Using std..
Class List<T> Extension
Operator []:T(index:Int)
Assert(index = 0 Or index < Count())
' INTERNAL IMPLEMENTATION (UNTESTED)
' Local count := Count()
' Local node := _head._succ
' For Local i := 0 Until count
' If i = index Then Return node._value
' node=node._succ
' Next
' Return Null
' EXTENDED IMPLEMENTATION
Local count := 0
For Local item := Eachin Self
If count = index Then Return item
count += 1
End
Return Null
End
Method IndexOf:Int(value:T)
Local count := 0
For Local item := Eachin Self
If item = value Then Return count
count += 1
End
' perhaps could return -1 but messing with array indices not seem smart
' also could return 0 but might not make sense, you ask for i3 and you get i0
' for now Null should be abvious, unless an integer is chosen for a good reason
Return Null
End
End
Function Main()
Local fruits := New List<String>
fruits.AddAll(New String[] ("Apple", "Strawberry", "Orange", "Banana"))
Print(fruits[0] + " " + fruits[3])
Print("Index of " + fruits[2] + " = " + fruits.IndexOf(fruits[2]))
End