include "list"
(* map is included in list, this is that just without type annotations *)
function map2(theList, transform) do
val index := 0
val newList := []
while index < theList.size() do
newList[index] := transform(theList[index])
index := index + 1
end
return newList
end
(* this is a demonstration of higher order functions *)
function add(a: integer, b: integer) do
return a + b
end
(* Fill the first argument of a function and return a function to take the second *)
function apply(fun, first) do
return function (second) do
return fun(first, second)
end
end
val printList := function(item) do
output item
end
val increment := apply(add, 1)
val decrement := apply(add, -1)
[1,2,3].map2(increment).forEach(printList)
(* This will fail as it has detected that you applying an integer function on a text list*)
(* ["test", "ing", "text"].map2(increment).forEach(printList) *)