Task

Take a combined set of elements and apply a function to each element.




square = fn (N) {
    N * N
}
 
# list comprehension
squares1 = fn (Numbers) {
    [square(N) for N in Numbers]
}
 
# functional form
squares2a = fn (Numbers) {
    lists.map(fn square:1, Numbers)
}
 
# functional form with lambda
squares2b = fn (Numbers) {
    lists.map(fn (N) { N * N }, Numbers)
}
 
# no need for a function
squares3 = fn (Numbers) {
    [N * N for N in Numbers]
}
 
@public
run = fn () {
    Numbers = [1, 3, 5, 7]
    io.format("squares1 : ~p~n", [squares1(Numbers)])
    io.format("squares2a: ~p~n", [squares2a(Numbers)])
    io.format("squares2b: ~p~n", [squares2b(Numbers)])
    io.format("squares3 : ~p~n", [squares3(Numbers)])
}
 