You are previewing Introducing Elixir.
O'Reilly logo
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.

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
    6. Writing Unit Tests
  12. 11. 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
  13. 12. Getting Started with OTP
    1. Creating Services with gen_server
    2. A Simple Supervisor
    3. Packaging an Application with Mix
  14. 13. 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
  15. 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
  16. B. Generating Documentation with ExDoc
    1. Using ExDoc with mix
  17. Index
  18. Colophon
  19. Copyright