Book Image

Elixir Cookbook

By : Paulo Pereira
Book Image

Elixir Cookbook

By: Paulo Pereira

Overview of this book

Table of Contents (16 chapters)
Elixir Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Combining operations with the |> operator


In this recipe, we will make use of the pipe operator (|>) to create a series of transformations in a text file.

The |> operator feeds the result of the left-hand side expression as the first argument of the right-hand side expression. It is possible to create complex transformations on data, giving the programmer a more immediate perception of the data flow.

We will parse a text file, make all characters uppercase, replace every vowel with @, and save it as a new file.

Getting ready

We will create a Mix project and escriptize it to allow us to run it from the command line without having to start an IEx session. The steps are as follows:

  1. Create a Mix project:

    > mix new pipe_transformation
    
  2. Edit the mix.exs file, adding the escript option so that def project looks like this:

        def project do
           [app: :pipe_transformation,
            version: "0.0.1",
            elixir: "~> 1.0.0",
            escript: [main_module: PipeTransformation],
          ...