O'Reilly logo

Elixir Cookbook by Paulo A Pereira

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required