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.
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:
Create a Mix project:
> mix new pipe_transformation
Edit the
mix.exs
file, adding theescript
option so thatdef project
looks like this:def project do [app: :pipe_transformation, version: "0.0.1", elixir: "~> 1.0.0", escript: [main_module: PipeTransformation], ...