Functions as Data

Since Elixir is a functional language, we should all remember that functions are data too. Sometimes using functions can offer tremendous performance wins.

For example, this is one way to store the drawing instructions for a square:

 iex(1)> square = [ {:line, {5, 0}, {15, 0}},
  {:line, {15, 0}, {15, 10}},
  {:line, {15, 10}, {5, 10}},
  {:line, {5, 10}, {5, 0}}]
 [
  {:line, {5, 0}, {15, 0}},
  {:line, {15, 0}, {15, 10}},
  {:line, {15, 10}, {5, 10}},
  {:line, {5, 10}, {5, 0}}
 ]

That way works fine. Each tuple has an instruction, a beginning point and an ending point. A CAD system would have an extensive list of such instructions. The problem comes when you start to partition work across processes. When Elixir moves across ...

Get Designing Elixir Systems With OTP now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.