Functions as Data
Explore Elixir's concept of functions as data within its datatype system. Understand the benefits of sending functions to data rather than transferring large datasets across processes, improving efficiency in distributed systems.
We'll cover the following...
We'll cover the following...
Remember that since Elixir is a functional language, all functions are data. Sometimes using functions can offer tremendous performance wins.
Drawing a square without a function
Here is one way to store the drawing instructions for a square:
Executable
Output
iex(1)> square = [ {:line, {5, 0}, {15, 0}},
...(1)> {:line, {15, 0}, {15, 10}},
...(1)> {:line, {15, 10}, {5, 10}},
...(1)> {:line, {5, 10}, {5, 0}}]
[
{:line, {5, 0}, {15, 0}},
{:line, ...