You are previewing Elixir Cookbook.
O'Reilly logo
Elixir Cookbook

Book Description

Unleash the full power of programming in Elixir with over 60 incredibly effective recipes

In Detail

This book is a set of recipes grouped by topic that acts as a good reference to get ideas from or to quickly search for a solution to a problem. You will begin by launching an IEx session and using it to test some ideas. Next, you will perform various operations like loading and compiling modules, inspecting your system, generating a supervised app, and so on. Furthermore, you will be introduced to immutability, working with data structures, performing pattern matching, and using stream modules to generate infinite data sequences. You will learn about everything from joining strings to determining the word frequency in text. With respect to modules and functions, you will also discover how to load code from other modules and use guards and pattern matching in functions.

What You Will Learn

  • Utilize Erlang code seamlessly from Elixir, leveraging a huge amount of battle-tested libraries

  • Use the Mix tool to generate applications and manage dependencies

  • Create modules and functions and use them from different machines, taking advantage of Elixir's integrated distribution mechanism

  • Implement OTP behaviors in Elixir

  • Package and deploy applications on running systems

  • Work with the Phoenix framework to generate a basic web application

  • Interact with external programs and APIs

  • Serve static files and implement websockets

  • Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.

    Table of Contents

    1. Elixir Cookbook
      1. Table of Contents
      2. Elixir Cookbook
      3. Credits
      4. About the Author
      5. About the Reviewers
      6. www.PacktPub.com
        1. Support files, eBooks, discount offers, and more
          1. Why Subscribe?
          2. Free Access for Packt account holders
      7. Preface
        1. What this book covers
        2. What you need for this book
        3. Who this book is for
        4. Sections
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
          5. See also
        5. Conventions
        6. Reader feedback
        7. Customer support
          1. Downloading the example code
          2. Errata
          3. Piracy
          4. Questions
      8. 1. Command Line
        1. Introduction
        2. Using the terminal to prototype and test ideas
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
        3. Loading and compiling modules
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
        4. Getting help and accessing documentation within IEx
          1. How to do it…
          2. How it works…
          3. There's more…
        5. Using Erlang from Elixir
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
        6. Inspecting your system in IEx
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. See also
        7. Inspecting your system with Observer
          1. Getting ready
          2. How to do it…
        8. Creating a simple application
          1. How to do it…
          2. How it works…
          3. See also
        9. Managing dependencies
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. See also
        10. Generating a supervised application
          1. How to do it…
          2. How it works…
          3. See also
        11. Generating umbrella applications
          1. How to do it…
          2. How it works…
          3. See also
        12. Managing application configuration
          1. How to do it…
          2. How it works…
        13. Creating custom Mix tasks
          1. How to do it…
          2. How it works…
      9. 2. Data Types and Structures
        1. Understanding immutability
          1. Getting ready
          2. How to do it…
          3. How it works…
        2. Adding and subtracting lists
          1. Getting ready
          2. How to do it…
          3. How it works…
        3. Combining tuples into a list
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. See also
        4. Creating and manipulating keyword lists
          1. Getting ready
          2. How to do it…
          3. How it works…
        5. Using pattern matching
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. See also
        6. Pattern matching an HTTPoison response
          1. Getting ready
          2. How to do it…
          3. How it works…
        7. Creating a key/value store with a map
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. See also
        8. Mapping and reducing enumerables
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There is more…
        9. Generating lazy (even infinite) sequences
          1. How to do it…
          2. How it works…
          3. There is more…
        10. Streaming a file as a resource
          1. Getting ready
          2. How to do it…
          3. How it works…
      10. 3. Strings and Binaries
        1. Introduction
        2. Joining strings
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
        3. Splitting strings
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. See also
        4. Replacing string codepoints with patterns
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. See also
        5. Slicing strings with ranges
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
        6. Using regular expressions
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. See also
        7. Combining operations with the |> operator
          1. Getting ready
          2. How to do it…
          3. How it works…
        8. Creating a word list
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
        9. Determining the word frequency in a text
          1. Getting ready
          2. How to do it…
          3. How it works…
        10. Reading and writing metadata from MP3 files
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
      11. 4. Modules and Functions
        1. Introduction
        2. Namespacing modules
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
        3. Using module attributes as constants
          1. How to do it…
          2. How it works…
          3. See also
        4. Enforcing behaviors
          1. How to do it…
          2. How it works…
          3. See also
        5. Documenting modules
          1. Getting ready
          2. How to do it…
        6. Using module directives
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
        7. Using a module in the scripted mode
          1. How to do it…
          2. How it works…
          3. There's more…
        8. Defining functions with default arguments
          1. Getting ready
          2. How to do it…
          3. How it works…
        9. Using guard clauses and pattern matching in function definitions
          1. Getting ready
          2. How to do it…
          3. How it works…
      12. 5. Processes and Nodes
        1. Introduction
        2. Sending messages between processes
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
        3. Making code run on all available CPUs
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
        4. Using tasks to perform multiple concurrent computations
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
        5. Creating a stateful server process (messages with counters)
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. See also
        6. Using agents as an abstraction around states
          1. How to do it…
          2. How it works…
          3. There's more…
        7. Using an ETS table to share the state
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
        8. Creating named nodes
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. See also
        9. Connecting nodes
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
          5. See also
        10. Executing code in a different node
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
      13. 6. OTP – Open Telecom Platform
        1. Introduction
        2. Implementing a GenServer
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
        3. Expanding our server
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. See also
        4. Creating a supervisor
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. See also
        5. Using Observer to inspect supervisors and processes
          1. How to do it…
          2. How it works…
        6. Handling errors and managing exceptions
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
        7. Packaging and releasing an OTP application
          1. Getting ready…
          2. How to do it…
          3. How it works…
          4. There's more…
          5. See also
        8. Deploying applications and updating a running system
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. See also
      14. 7. Cowboy and Phoenix
        1. Introduction
        2. Setting up Cowboy
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
          5. See also
        3. Serving static files
          1. Getting ready
          2. How to do it…
          3. How it works…
        4. Implementing a websocket handler
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
        5. Creating a Phoenix application
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
        6. Defining routes
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
          5. See also
        7. Creating a controller
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
        8. Creating views and templates
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
        9. Implementing topics
          1. Getting ready
          2. How to do it…
          3. How it works…
        10. Protecting the Phoenix app with SSL
          1. Getting ready
          2. How to do it…
          3. How it works…
      15. 8. Interactions
        1. Introduction
        2. Using Redis and Postgres
          1. Getting ready
          2. How to do it…
          3. How it works…
        3. Using OS commands from within Elixir
          1. How to do it…
          2. How it works…
          3. There's more…
          4. See also
        4. Getting Twitter data
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
          5. See also
      16. A. Installation and Further Reading
        1. Installing Elixir
        2. Installing PostgreSQL
        3. Installing Redis
        4. Some useful links
          1. Elixir
          2. The Phoenix framework
          3. Erlang
      17. Index