You are previewing Études for Elixir.
O'Reilly logo
Études for Elixir

Book Description

This book includes descriptions of programs that you can write in Elixir. The programs will usually be short, and each one has been designed to provide practice material for a particular Elixir programming concept. These programs have not been designed to be of considerable difficulty, though they may ask you to stretch a bit beyond the immediate material and examples that you find in the book Introducing Elixir.

Table of Contents

  1. Études for Elixir
    1. Contributor Guidelines
    2. How to Contribute
      1. Create a GitHub account
      2. Copy (“fork”) the project repository to your account
      3. Edit your file using AsciiDoc
      4. Double check your submission and add your biography
      5. Submit a pull request
      6. Engage in back-and-forth
  2. Preface: What’s an étude?
    1. What are Études for Elixir?
    2. How This Book was Written
    3. Elixir is a Young Language
    4. Acknowledgments
  3. 1. Getting Comfortable with Elixir
    1. Étude 1-1: Experimenting with Errors
  4. 2. Functions and Modules
    1. Étude 2-1: Writing a Function
    2. Étude 2-2: Writing a Function with Default Values
    3. Étude 2-3: Documenting a Module
    4. Étude 2-4: Discovery Étude
  5. 3. Atoms, Tuples, and Pattern Matching
    1. Étude 3-1: Pattern Matching
    2. Étude 3-2: Guards
    3. Étude 3-3: Underscores
    4. Étude 3-4: Tuples as Parameters
  6. 4. Logic and Recursion
    1. Étude 4-1: Using <code xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:pls="http://www.w3.org/2005/01/pronunciation-lexicon" xmlns:ssml="http://www.w3.org/2001/10/synthesis" xmlns:svg="http://www.w3.org/2000/svg" class="literal">case</code>
    2. Étude 4-2: Recursion
    3. Étude 4-3: Non-Tail Recursive Functions
    4. Étude 4-4: Tail Recursion with an Accumulator
    5. Étude 4-5: Recursion with a Helper Function
  7. 5. Strings
    1. Étude 5-1: Validating Input
    2. Étude 5-2: Better Validation with Regular Expressions
    3. Étude 5-3: Using String.split
  8. 6. Lists
    1. Étude 6-1: Recursive Iteration through a List
    2. Étude 6-2: Accumulating the Sum of a List
    3. Interlude: “Mistakes were made.”
    4. Étude 6-3: Lists of Lists
    5. Étude 6-4: Random Numbers; Generating Lists of Lists
  9. 7. Hashes
    1. Étude 7-1: Creating a HashDict from a File
      1. Opening Files
    2. Étude 7-2: Creating Structures from a File
    3. Étude 7-3: Using Structures
    4. Étude 7-4: Protocols with Structures
  10. 8. Higher Order Functions and List Comprehensions
    1. Étude 8-1: Simple Higher Order Functions
    2. Étude 8-2: List Comprehensions and Pattern Matching
    3. Étude 8-3: Using <code xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:pls="http://www.w3.org/2005/01/pronunciation-lexicon" xmlns:ssml="http://www.w3.org/2001/10/synthesis" xmlns:svg="http://www.w3.org/2000/svg" class="literal">lists:foldl/3</code>
    4. Étude 8-4: Using <code xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:pls="http://www.w3.org/2005/01/pronunciation-lexicon" xmlns:ssml="http://www.w3.org/2001/10/synthesis" xmlns:svg="http://www.w3.org/2000/svg" class="literal">Enum.split/2</code>
    5. Étude 8-5: Multiple Generators in List Comprehensions
    6. Étude 8-6: Explaining an Algorithm
  11. 9. Processes
    1. Étude 9-1: Using Processes to Simulate a Card Game
      1. The Art of War
      2. War: What is it good for?
      3. Pay Now or Pay Later
      4. The Design
      5. Messages Are Asynchronous
      6. Hints for Testing
  12. 10. Handling Errors
    1. Étude 10-1: <code xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:pls="http://www.w3.org/2005/01/pronunciation-lexicon" xmlns:ssml="http://www.w3.org/2001/10/synthesis" xmlns:svg="http://www.w3.org/2000/svg" class="literal">try</code> and and <code xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:pls="http://www.w3.org/2005/01/pronunciation-lexicon" xmlns:ssml="http://www.w3.org/2001/10/synthesis" xmlns:svg="http://www.w3.org/2000/svg" class="literal">rescue</code>
    2. Étude 10-2: Logging Errors
  13. 11. Storing Structured Data
    1. Étude 11-1: Using ETS
      1. Part One
      2. Part Two
  14. 12. Getting Started with OTP
    1. Étude 12-1: Get the Weather
      1. Obtaining Weather Data
      2. Parsing the Data
      3. Set up a Supervisor
    2. Étude 12-2: Wrapper Functions
    3. Étude 12-3: Independent Server and Client
    4. Étude 12-4: Chat Room
      1. The <code xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:pls="http://www.w3.org/2005/01/pronunciation-lexicon" xmlns:ssml="http://www.w3.org/2001/10/synthesis" xmlns:svg="http://www.w3.org/2000/svg" class="literal">Chatroom</code> Module Module
      2. The <code xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:pls="http://www.w3.org/2005/01/pronunciation-lexicon" xmlns:ssml="http://www.w3.org/2001/10/synthesis" xmlns:svg="http://www.w3.org/2000/svg" class="literal">Person</code> Module Module
      3. Wrapper Functions for the <code xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:pls="http://www.w3.org/2005/01/pronunciation-lexicon" xmlns:ssml="http://www.w3.org/2001/10/synthesis" xmlns:svg="http://www.w3.org/2000/svg" class="literal">Person</code> module module
      4. Putting it All Together
  15. 13. Using Macros to Extend Elixir
    1. Étude 13-1: Atomic weights
    2. Étude 13-2: Adding Durations
    3. Étude 13-3: Adding Durations (operator version)
  16. 14. Contributors
  17. A. Solutions to Études
    1. Solution 2-1
    2. Solution 2-2
    3. Solution 2-3
    4. Solution 3-1
    5. Solution 3-2
    6. Solution 3-3
    7. Solution 3-4
    8. Solution 4-1
    9. Solution 4-2
    10. Solution 4-2
    11. Solution 4-3
    12. Solution 4-4
    13. Solution 4-5
    14. Solution 5-1
    15. Solution 5-2
    16. Solution 5-3
    17. Solution 6-1
    18. Solution 6-2
    19. Solution 6-3
    20. Solution 6-4
    21. Solution 7-1
    22. Solution 7-1
    23. Solution 7-3
    24. Solution 7-4
    25. Solution 8-1
    26. Solution 8-2
    27. Solution 8-3
    28. Solution 8-4
    29. Solution 8-5
    30. Solution 8-6
    31. Solution 9-1
    32. Solution 10-1
    33. Solution 10-2
    34. Solution 11-1
    35. Solution 12-1
    36. Solution 12-2
    37. Solution 12-3
    38. Solution 12-4
    39. Solution 13-1
    40. Solution 13-2
    41. Solution 13-3
  18. B. A Brief Introduction to Regular Expressions
    1. The Simplest Patterns
    2. Matching Sets of Characters
    3. Anchors
    4. Repetition
  19. Copyright