struct MyList:
var list: List[Int]
fn __init__(out self):
self.list = List[Int]()
fn __getitem__(self, index: Int) -> ref[self.list] Int:
return self.list[index]
fn append(mut self, value: Int) -> None:
self.list.append(value)
fn do_stuff(mut self, index: Int) -> None:
self.list[index] = 1
fn main() raises -> None:
var mylist = MyList()
mylist.append(0)
var q1 = mylist[0]
print(q1)
mylist.do_stuff(0)
print(q1)
print(mylist[0])
struct MyList:
var list: List[Int]
fn __init__(out self):
self.list = List[Int]()
fn __getitem__(self, index: Int) -> ref[self.list] Int:
return self.list[index]
fn append(mut self, value: Int) -> None:
self.list.append(value)
fn do_stuff(mut self, index: Int) -> None:
self.list[index] = 1
fn main() raises -> None:
var mylist = MyList()
mylist.append(0)
var q1 = mylist[0]
print(q1)
mylist.do_stuff(0)
print(q1)
print(mylist[0])