Elixir structure
So far, we haven't seen much more than tiny snippets, demonstrating a fraction of the syntax of Elixir. Now we are going to go into more detail and look at some more in-depth examples.
We will start with what may be considered a functional language's real "hello world", the map
function.
Note
Note that this example will use some concepts that we are going to go into more detail in the next few chapters.
The map
function essentially takes a function and a list, and applies the function to each element in the list. Ideally, the application of one element in the list does not depend or effect any other application of any other element. Thus, this is usually something that can be trivial (in concept) to parallelize. However, very few languages make it so easy as the functional languages, and in particular, Elixir.
Using what we know now (and some stuff we haven't covered), here's how we might write our own map
function:
defmodule MyMap do def map(...