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:
Nathan Braswell
2015-06-08 21:47:02 -04:00
parent 69048ebc31
commit 47bc52f00c
19 changed files with 188 additions and 48 deletions

View File

@@ -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
}
};