January 2020
Intermediate to advanced
532 pages
13h 31m
English
Sometimes, we just want to create a simple function and pass it around without assigning it a name. This style of programming is actually fairly common in functional programming languages. We can illustrate its use with an example.
Suppose that we want to explode all of the asteroids. One way to do this is to define an explode function and pass it into the foreach function as follows:
function explode(x) println(x, " exploded!")endfunction clean_up_galaxy(asteroids) foreach(explode, asteroids)end
The results look good:

We can achieve the same effect if we just pass an anonymous function into foreach:
function ...
Read now
Unlock full access