Smooth, powerful, and small, Elixir is an excellent language for learning functional programming, and with this hands-on introduction, you’ll discover just how powerful Elixir can be. Authors Simon St. Laurent and J. David Eisenberg show you how Elixir combines the robust functional programming of Erlang with an approach that looks more like Ruby, and includes powerful macro features for metaprogramming.
Updated to cover Elixir 1.4, the second edition of this practical book helps you write simple Elixir programs by teaching one skill at a time. Once you pick up pattern matching, process-oriented programming, and other concepts, you’ll understand why Elixir makes it easier to build concurrent and resilient programs that scale up and down with ease.
Get comfortable with IEx, Elixir’s command line interface
Learn Elixir’s basic structures by working with numbers
Discover atoms, pattern matching, and guards: the foundations of your program structure
Delve into the heart of Elixir processing with recursion, strings, lists, and higher-order functions
Create Elixir processes and send messages among them
Store and manipulate structured data with Erlang Term Storage and the Mnesia database
Build resilient applications with the Open Telecom Platform
Chapter 1Getting Comfortable
Firing It Up
Numbers in Elixir
Working with Variables in the Shell
Chapter 2Functions and Modules
Fun with fn
And the &
From Module to Free-Floating Function
Splitting Code Across Modules
Combining Functions with the Pipe Operator
Default Values for Arguments
Chapter 3Atoms, Tuples, and Pattern Matching
Pattern Matching with Atoms
Underscoring That You Don’t Care
Adding Structure: Tuples
Chapter 4Logic and Recursion
Logic Inside of Functions
The Gentlest Side Effect: IO.puts
Chapter 5Communicating with Humans
Asking Users for Information
Splitting Lists into Heads and Tails
Processing List Content
Creating Lists with Heads and Tails
Mixing Lists and Tuples
Building a List of Lists
Chapter 7Name-Value Pairs
Lists of Tuples with Multiple Keys
From Lists to Maps
From Maps to Structs
Chapter 8Higher-Order Functions and List Comprehensions
Simon St. Laurent is a Content Manager at LinkedIn Learning, focusing primarily on the client side of the web. He is a past co-chair of the Fluent and OSCON conferences. He's authored or co-authored books including Introducing Elixir, Introducing Erlang, Learning Rails 3, XML Pocket Reference, 3rd edition, XML: A Primer, and Cookies.
You can find more of his writing on technology, Quakerism, and the Town of Dryden at simonstl.com.
The animal on the cover of Introducing Elixir is a four-horned antelope (Tetracerus quadricornis), found in India and Nepal. Also called chousingha, these antelope are the smallest of Asian bovids, standing at 22 to 25 inches at the shoulder and weighing from 37 to 49 pounds. They have a slender build with thin legs and short tails, and a yellow-brown or reddish coat that fades to white on the underbelly and inner legs. They also have a black stripe of hair that runs down each leg. The antelope's most distinctive features are the four horns seen on males: two between the ears, which grow in at just a few months' age, and two on the forehead, which grow in after 10 to 14 months. The front pair can reach about 2 inches whereas the hind pair can grow nearly 4 inches in length.
Four-horned antelope tend to live near a water supply and in areas with significant vegetation cover, such as from tall grass or heavy undergrowth. They are generally solitary animals, occasionally found in groups of up to four, and they tend to avoid human-inhabited areas. During mating season—May to July—males can become aggressive toward other males. Gestation lasts around eight months and usually results in one or two young, which remain with their mothers for about a year, reaching sexual maturity at two years.
The antelope communicate through alarm calls, which sound like a husky "phronk," and through scent marking (leaving piles of droppings to mark their territory or using large scent glands in front of their eyes to mark vegetation).
Because they live in such a densely populated area of the world, the four-horned antelope's natural habitat is threatened by agricultural development. This species is listed as Vulnerable by the International Union for Conservation of Nature (IUCN) because of habitat loss. They have also become a target for trophy hunters who seek their unusual horned skull. There are estimated to be only around 10,000 individuals of this species left in the wild; many are being protected in animal conservatories. The four-horned antelope is protected under the Indian Wildlife Protection Act.
Many of the animals on O'Reilly covers are endangered; all of them are important to the world. To learn more about how you can help, go to animals.oreilly.com.