Work on function value lower

This commit is contained in:
Nathan Braswell
2017-02-02 00:46:36 -05:00
parent 754ff41226
commit 1b0dce9ed1
5 changed files with 117 additions and 1 deletions

View File

@@ -82,6 +82,9 @@ obj set<T> (Object, Serializable) {
fun add(items: ref set<T>) {
items.for_each( fun(item: ref T) add(item); )
}
fun add(items: ref vector::vector<T>) {
items.for_each( fun(item: ref T) add(item); )
}
fun remove(item: ref T) {
var idx = data.find(item)
if (idx == -1) {
@@ -102,6 +105,12 @@ obj set<T> (Object, Serializable) {
fun reduce<U>(func: fun(T,U): U, initial: U): U {
return data.reduce(func, initial)
}
fun map<U>(func: fun(T):U):set<U> {
var newSet.construct(size()): set<U>
for (var i = 0; i < size(); i++;)
newSet.add(func(data[i]))
return newSet
}
fun flatten_map<U>(func: fun(T):set<U>):set<U> {
var newSet.construct(size()): set<U>
for (var i = 0; i < size(); i++;)