Created
July 29, 2020 22:29
-
-
Save anthonykasza/cec6aa1e398f684e79417428e3913c7b to your computer and use it in GitHub Desktop.
map-example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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