February 2018
Beginner
200 pages
4h 37m
English
Higher-order functions are those that have functions in their arguments and/or can return functions. They are useful for hiding the complexity of tedious and laborious routines. Having functions in input and output enables developers to create simple interfaces to help other parts of the code focus on what matters. For example, let’s try File.open/3 in an IEx session:
| | iex> File.open("file.txt", [:write], &(IO.write(&1, "Hello, World!"))) |
The last argument of File.open/3 is a function that receives the file device. We can write and read its contents using the IO module. The main benefit of using it in this way is we don’t need to worry if the file will be closed, because it will. Another example ...
Read now
Unlock full access