O'Reilly logo

Programming Elixir by Dave Thomas

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

|> — The Amazing Pipe Operator

I’ve saved the best for last, at least when it comes to functions.

You’ve all seen code like this:

 
people = DB.find_customers
 
orders = Orders.for_customers(people)
 
tax = sales_tax(orders, 2013)
 
filing = prepare_filing(tax)

Bread-and-butter programming. We did it because the alternative was to write

 
filing = prepare_filing(sales_tax(Orders.for_customers(DB.find_customers), 2013))

and that’s the kind of code that you use to get kids to eat their vegetables. Not only is it hard to read, but you have to read it inside out if you want to see the order in which things get done.

Elixir has a better way of writing it.

 
filing = DB.find_customers
 
|> Orders.for_customers
 
|> sales_tax(2013)
 
|> prepare_filing

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required