Skip to content

Instantly share code, notes, and snippets.

@anthonykasza
Created July 29, 2020 22:29
Show Gist options
  • Save anthonykasza/cec6aa1e398f684e79417428e3913c7b to your computer and use it in GitHub Desktop.
Save anthonykasza/cec6aa1e398f684e79417428e3913c7b to your computer and use it in GitHub Desktop.
map-example
# An example of using custom types to implement map/filter functionality in scriptland
global v: vector of int = {-10, -1, 0, 1, 10, -999};
type map_func: function(a: any): any;
global positive_filter: map_func;
function map(v1: vector of any, mf: map_func): vector of any {
local v2: vector of any;
for (idx in v1) {
v2 += mf(v1[idx]);
}
return v2;
}
function positive_filter(i: int): bool {
if (i > 0) {
return T;
}
return F;
}
print map(v, positive_filter);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment