Introducing Elixir

Book description

Elixir is an excellent language if you want to learn about functional programming, and with this hands-on introduction, you’ll discover just how powerful and fun Elixir can be. This language combines the robust functional programming of Erlang with a syntax similar to Ruby, and includes powerful features for metaprogramming.

Publisher resources

View/Submit Errata

Table of contents

  1. Preface
    1. Who This Book Is For
    2. Who This Book Is Not For
    3. What This Book Will Do For You
    4. How This Book Works
    5. Other Resources
    6. Elixir Will Change You
    7. Conventions Used in This Book
    8. Using Code Examples
    9. Help This Book Grow
    10. Please Use It For Good
    11. Safari® Books Online
    12. How to Contact Us
    13. Acknowledgments
  2. 1. Getting Comfortable
    1. Installation
      1. Installing Erlang
      2. Installing Elixir
    2. Firing It Up
    3. First Steps
      1. Moving Through Text and History
      2. Moving Through Files
    4. Doing Something
    5. Calling Functions
    6. Numbers in Elixir
    7. Working with Variables in the Shell
  3. 2. Functions and Modules
    1. Fun with fn
    2. And the &
    3. Defining Modules
    4. From Module to Free-Floating Function
    5. Splitting Code Across Modules
    6. Combining Functions with the Pipe Operator
    7. Importing Functions
    8. Default Values for Arguments
    9. Documenting Code
    10. Documenting Functions
    11. Documenting Modules
  4. 3. Atoms, Tuples, and Pattern Matching
    1. Atoms
    2. Pattern Matching with Atoms
    3. Atomic Booleans
    4. Guards
    5. Underscoring That You Don’t Care
    6. Adding Structure: Tuples
      1. Pattern Matching with Tuples
      2. Processing Tuples
  5. 4. Logic and Recursion
    1. Logic Inside of Functions
      1. Evaluating Cases
      2. Adjusting to Conditions
      3. If, or else
      4. Variable Assignment in case and if Constructs
    2. The Gentlest Side Effect: IO.puts
    3. Simple Recursion
      1. Counting Down
      2. Counting Up
      3. Recursing with Return Values
  6. 5. Communicating with Humans
    1. Strings
    2. Multiline Strings
    3. Unicode
    4. Character Lists
    5. String Sigils
    6. Asking Users for Information
      1. Gathering Characters
      2. Reading Lines of Text
  7. 6. Lists
    1. List Basics
    2. Splitting Lists into Heads and Tails
    3. Processing List Content
    4. Creating Lists with Heads and Tails
    5. Mixing Lists and Tuples
    6. Building a List of Lists
  8. 7. Name-Value Pairs
    1. Keyword Lists
    2. Lists of Tuples with Multiple Keys
    3. Hash Dictionaries
    4. From Lists to Maps
      1. Creating Maps
      2. Updating Maps
      3. Reading Maps
    5. From Maps to Structs
      1. Setting Up Structs
      2. Creating and Reading Structs
      3. Pattern Matching Against Structs
      4. Using Structs in Functions
      5. Adding Behavior to Structs
      6. Adding to Existing Protocols
  9. 8. Higher-Order Functions and List Comprehensions
    1. Simple Higher-Order Functions
    2. Creating New Lists with Higher-Order Functions
      1. Reporting on a List
      2. Running List Values Through a Function
      3. Filtering List Values
    3. Beyond List Comprehensions
      1. Testing Lists
      2. Splitting Lists
      3. Folding Lists
  10. 9. Playing with Processes
    1. The Shell Is a Process
    2. Spawning Processes from Modules
    3. Lightweight Processes
    4. Registering a Process
    5. When Processes Break
    6. Processes Talking Amongst Themselves
    7. Watching Your Processes
      1. Watching Messages Among Processes
    8. Breaking Things and Linking Processes
  11. 10. Exceptions, Errors, and Debugging
    1. Flavors of Errors
    2. Rescuing Code from Runtime Errors as They Happen
    3. Logging Progress and Failure
    4. Tracing Messages
    5. Watching Function Calls
  12. 11. Static Analysis, Typespecs, and Testing
    1. Static Analysis
    2. Typespecs
    3. Writing Unit Tests
    4. Setting up Tests
    5. Embedding Tests in Documentation
  13. 12. Storing Structured Data
    1. Records: Structured Data Before structs
      1. Setting Up Records
      2. Creating and Reading Records
      3. Using Records in Functions
    2. Storing Data in Erlang Term Storage
      1. Creating and Populating a Table
      2. Simple Queries
      3. Overwriting Values
      4. ETS Tables and Processes
      5. Next Steps
    3. Storing Records in Mnesia
      1. Starting up Mnesia
      2. Creating Tables
      3. Reading Data
  14. 13. Getting Started with OTP
    1. Creating Services with gen_server
    2. A Simple Supervisor
    3. Packaging an Application with Mix
  15. 14. Using Macros to Extend Elixir
    1. Functions versus Macros
    2. A Simple Macro
    3. Creating New Logic
    4. Creating Functions Programatically
    5. When (Not) to Use Macros
    6. Sharing the Gospel of Elixir
  16. 15. Using Phoenix
    1. Skeleton installation
    2. Structuring a Basic Phoenix Application
    3. Presenting a Page
      1. Routing
      2. A Simple Controller
      3. A Simple View
    4. Calculating
  17. A. An Elixir Parts Catalog
    1. Shell Commands
    2. Reserved Words
    3. Operators
    4. Guard Components
    5. Common Functions
    6. Datatypes for Documentation and Analysis
  18. B. Generating Documentation with ExDoc
    1. Using ExDoc with mix
  19. Index

Product information

  • Title: Introducing Elixir
  • Author(s): Simon St. Laurent, J. David Eisenberg
  • Release date: September 2014
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9781449369996