Some bugfixes, allow overloading of [] and add that to vector and string, work on regex. Need closures before that finishes....
This commit is contained in:
@@ -74,10 +74,8 @@ obj vector<T> (Object) {
|
||||
return true;
|
||||
}
|
||||
|
||||
fun at(index: int): T {
|
||||
return get(index);
|
||||
}
|
||||
|
||||
fun at(index: int): T { return get(index); }
|
||||
fun operator[](index: int): T { return get(index); }
|
||||
fun get(index: int): T {
|
||||
if (index < 0 || index >= size) {
|
||||
println("Vector access out of bounds! Retuning 0th element as sanest option");
|
||||
@@ -97,6 +95,7 @@ obj vector<T> (Object) {
|
||||
return;
|
||||
data[index] = dataIn;
|
||||
}
|
||||
fun add(dataIn: T): void { addEnd(dataIn); }
|
||||
fun addEnd(dataIn: T): void {
|
||||
size++;
|
||||
if (size >= available)
|
||||
@@ -117,5 +116,20 @@ obj vector<T> (Object) {
|
||||
newVec.addEnd(func(data[i]))
|
||||
return newVec
|
||||
}
|
||||
fun flatten_map<U>(func: fun(T):vector<U>):vector<U> {
|
||||
var newVec.construct(): vector<U>
|
||||
for (var i = 0; i < size; i++;) {
|
||||
var to_add = func(data[i])
|
||||
for (var j = 0; j < to_add.size; j++;)
|
||||
newVec.addEnd(to_add.get(j))
|
||||
}
|
||||
return newVec
|
||||
}
|
||||
fun any_true(func: fun(T):bool):bool {
|
||||
for (var i = 0; i < size; i++;)
|
||||
if (func(data[i]))
|
||||
return true
|
||||
return false
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user