Programming Elixir

Book Description

You want to explore functional programming, but are put off by the academic feel (tell me about monads just one more time). You know you need concurrent applications, but also know these are almost impossible to get right. Meet Elixir, a functional, concurrent language built on the rock-solid Erlang VM. Elixir's pragmatic syntax and built-in support for metaprogramming will make you productive and keep you interested for the long haul. This book is the introduction to Elixir for experienced programmers.

Maybe you need something that's closer to Ruby, but with a battle-proven environment that's unrivaled for massive scalability, concurrency, distribution, and fault tolerance. Maybe the time is right for the Next Big Thing. Maybe it's Elixir.

And don't forget to download this handy "cheat sheet":​elixir/ElixirCheat.pdf for Elixir syntax.

As a developer, you've probably heard that functional programming techniques help manage the complexities of today's real-world, concurrent systems. You're also investigating designs that help you maximize uptime and manage security.

This book is your guide to Elixir, a modern, functional, and concurrent programming language. Because Elixir runs on the Erlang VM, and uses the underlying Erlang/OTP architecture, it benefits from almost 20 years of research into high performance, highly parallel, and seriously robust applications. Elixir brings a lot that's new: a modern, Ruby-like, extendable syntax, compile and runtime evaluation, a hygienic macro system, and more.

But, just as importantly, Elixir brings a sense of enjoyment to parallel, functional programming. Your applications become fun to work with, and the language encourages you to experiment.

Part 1 covers the basics of writing sequential Elixir programs. We'll look at the language, the tools, and the conventions.

Part 2 uses these skills to start writing concurrent code--applications that use all the cores on your machine, or all the machines on your network! And we do it both with and without OTP.

And Part 3 looks at the more advanced features of the language, from DSLs and code generation to extending the syntax.

By the end of this book, you'll understand Elixir, and know how to apply it to solve your complex, modern problems.

Publisher Resources

View/Submit Errata

Table of Contents

  1. Programming Elixir
    1. Copyright
    2. For the Best Reading Experience...
    3. Table of Contents
    4. Early praise for Programming Elixir
    5. Foreword
    6. A Vain Attempt at a Justification
      1. Acknowledgments
    7. Chapter 1: Take the Red Pill
      1. Programming Should Be About Transforming Data
      2. Installing Elixir
      3. Running Elixir
      4. Suggestions for Reading the Book
      5. Exercises
      6. Think Different(ly)
    8. Part 1: Conventional Programming
      1. Chapter 2: Pattern Matching
        1. Assignment: I Do Not Think It Means What You Think It Means.
        2. More Complex Matches
        3. Your Turn
        4. Ignoring a Value with _ (Underscore)
        5. Variables Bind Once (per Match)
        6. Your Turn
        7. Another Way of Looking at the Equals Sign
      2. Chapter 3: Immutability
        1. You Already Have (Some) Immutable Data
        2. Immutable Data Is Known Data
        3. Performance Implications of Immutability
        4. Coding with Immutable Data
      3. Chapter 4: Elixir Basics
        1. Built-in Types
        2. Value Types
        3. System Types
        4. Collection Types
        5. Maps
        6. Names, Source Files, Conventions, Operators, and So On
        7. End of the Basics
      4. Chapter 5: Anonymous Functions
        1. Functions and Pattern Matching
        2. Your Turn
        3. One Function, Multiple Bodies
        4. Your Turn
        5. Functions Can Return Functions
        6. Your Turn
        7. Passing Functions As Arguments
        8. Your Turn
        9. Functions Are the Core
      5. Chapter 6: Modules and Named Functions
        1. Compiling a Module
        2. The Function’s Body Is a Block
        3. Your Turn
        4. Function Calls and Pattern Matching
        5. Your Turn
        6. Guard Clauses
        7. Default Parameters
        8. Your Turn
        9. Private Functions
        10. | > — The Amazing Pipe Operator
        11. Modules
        12. Module Attributes
        13. Module Names: Elixir, Erlang, and Atoms
        14. Calling a Function in an Erlang Library
        15. Finding Libraries
        16. Your Turn
      6. Chapter 7: Lists and Recursion
        1. Heads and Tails
        2. Using Head and Tail to Process a List
        3. Using Head and Tail to Build a List
        4. Creating a Map Function
        5. Keeping Track of Values During Recursion
        6. Your Turn
        7. Your Turn
        8. More Complex List Patterns
        9. Your Turn
        10. The List Module in Action
        11. Get Friendly with Lists
      7. Chapter 8: Dictionaries: Maps, HashDicts, Keywords, Sets, and Structs
        1. How to Choose Between Maps, HashDicts, and Keywords
        2. Dictionaries
        3. Pattern Matching and Updating Maps
        4. Updating a Map
        5. Sets
        6. With Great Power Comes Great Temptation
      8. Chapter 9: An Aside—What Are Types?
      9. Chapter 10: Processing Collections—Enum and Stream
        1. Enum—Processing Collections
        2. Your Turn
        3. Streams—Lazy Enumerables
        4. The Collectable Protocol
        5. Comprehensions
        6. Your Turn
        7. Moving Past Divinity
      10. Chapter 11: Strings and Binaries
        1. String Literals
        2. The Name “strings”
        3. Single-Quoted Strings—Lists of Character Codes
        4. Your Turn
        5. Binaries
        6. Double-Quoted Strings Are Binaries
        7. Your Turn
        8. Binaries and Pattern Matching
        9. Your Turn
        10. Familiar Yet Strange
      11. Chapter 12: Control Flow
        1. if and unless
        2. cond
        3. case
        4. Raising Exceptions
        5. Designing with Exceptions
        6. Doing More with Less
        7. Your Turn
      12. Chapter 13: Organizing a Project
        1. The Project: Fetch Issues from GitHub
        2. Task: Use Mix to Create Our New Project
        3. Transformation: Parse the Command Line
        4. Step: Write Some Basic Tests
        5. Your Turn
        6. Transformation: Fetch from GitHub
        7. Task: Use External Libraries
        8. Your Turn
        9. Transformation: Convert Response
        10. Transformation: Sort Data
        11. Transformation: Take First n Items
        12. Your Turn
        13. Transformation: Format the Table
        14. Task: Make a Command-Line Executable
        15. Task: Add Some Logging
        16. Task: Test the Comments
        17. Task: Create Project Documentation
        18. Coding by Transforming Data
        19. Your Turn
    9. Part 2: Concurrent Programming
      1. Chapter 14: Working with Multiple Processes
        1. A Simple Process
        2. Process Overhead
        3. Your Turn
        4. When Processes Die
        5. Your Turn
        6. Parallel Map—The “Hello, World” of Erlang
        7. Your Turn
        8. A Fibonacci Server
        9. Your Turn
        10. Agents—A Teaser
        11. Thinking in Processes
      2. Chapter 15: Nodes—The Key to Distributing Services
        1. Naming Nodes
        2. Your Turn
        3. Naming Your Processes
        4. Your Turn
        5. I/O, PIDs, and Nodes
        6. Your Turn
        7. Nodes Are the Basis of Distribution
      3. Chapter 16: OTP: Servers
        1. Some OTP Definitions
        2. An OTP Server
        3. Your Turn
        4. Your Turn
        5. GenServer Callbacks
        6. Naming a Process
        7. Tidying Up the Interface
        8. Your Turn
      4. Chapter 17: OTP: Supervisors
        1. Supervisors and Workers
        2. Your Turn
        3. Supervisors Are the Heart of Reliability
        4. Your Turn
      5. Chapter 18: OTP: Applications
        1. This Is Not Your Father’s Application
        2. The Application Specification File
        3. Turning Our Sequence Program into an OTP Application
        4. Supervision Is the Basis of Reliability
        5. Your Turn
        6. Hot Code-Swapping
        7. OTP Is Big—Unbelievably Big
        8. Your Turn
      6. Chapter 19: Tasks and Agents
        1. Tasks
        2. Agents
        3. A Bigger Example
        4. Agents and Tasks, or GenServer?
    10. Part 3: More-Advanced Elixir
      1. Chapter 20: Macros and Code Evaluation
        1. Implementing an if Statement
        2. Macros Inject Code
        3. Using the Representation As Code
        4. Your Turn
        5. Using Bindings to Inject Values
        6. Macros Are Hygienic
        7. Other Ways to Run Code Fragments
        8. Macros and Operators
        9. Digging Deeper
        10. Digging Ridiculously Deep
        11. Your Turn
      2. Chapter 21: Linking Modules: Behavio(u)rs and Use
        1. Behaviours
        2. Use and __using__
        3. Putting It Together—Tracing Method Calls
        4. Use use
        5. Your Turn
      3. Chapter 22: Protocols—Polymorphic Functions
        1. Defining a Protocol
        2. Implementing a Protocol
        3. The Available Types
        4. Your Turn
        5. Protocols and Structs
        6. Protocols Are Polymorphism
        7. Your Turn
      4. Chapter 23: More Cool Stuff
        1. Writing Your Own Sigils
        2. Your Turn
        3. Multi-app Umbrella Projects
        4. But Wait! There’s More!
    11. Appendix 1: Exceptions: raise and try, catch and throw
      1. Raising an Exception
      2. catch, exit, and throw
      3. Defining Your Own Exceptions
      4. Now Ignore This Appendix
    12. Appendix 2: Type Specifications and Type Checking
      1. When Specifications Are Used
      2. Specifying a Type
      3. Defining New Types
      4. Specs for Functions and Callbacks
      5. Using Dialyzer
    13. Bibliography
      1. You May Be Interested In…

Product Information

  • Title: Programming Elixir
  • Author(s):
  • Release date: October 2014
  • Publisher(s): Pragmatic Bookshelf
  • ISBN: 9781937785581