Simple Functions

Learn how to write functions in Elixir from scratch.

We'll cover the following

Elixir is a functional language, so it’s no surprise that functions are a basic type. An anonymous function is created using the fn keyword: fn parameter-list -> body end.

Think of fn...end as being a bit like the quotes that surround a string literal, except here, we’re returning a function as a value, not a string. We can pass that function value to other functions. We can also invoke it, passing in arguments.

Get hands-on with 1400+ tech skills courses.