Elixir Tips

Elixir Tips

  • Alexander Koutmos

    akoutmos

    akoutmos

    Simple stream data processing

    The Enum and Stream modules complement each other quite nicely and can be used for easy and effective data processing. Take a look at how you can stream process a CSV file!
    # $ cat ./expenses.csv
    
    # # System76 Lemur Pro,1499.99
    
    # # MacBook Air,1999.99
    
    # # AMD Ryzen 3950x,749.99
    
    # ...
    
    
    iex> "./expenses.csv" |>
    ...> File.stream!() |>
    ...> Stream.map(fn line ->
    ...>   line |>
    ...>   String.trim() |>
    ...>   String.split(",") |>
    ...>   Enum.at(1) |>
    ...>   String.to_float()
    ...> end |>
    ...> Enum.sum()
    4249.97
    
    33 upvotes