O'Reilly logo

Programming Elixir by Dave Thomas

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

Transformation: Format the Table

All that’s left from our design is to create the formatted table. This would be a nice interface:

 
def​ process({user, project, count}) ​do
 
Issues.GithubIssues.fetch(user, project)
 
|> decode_response
 
|> convert_to_list_of_hashdicts
 
|> sort_into_ascending_order
 
|> Enum.take(count)
*
|> print_table_for_columns([​"number"​, ​"created_at"​, ​"title"​])
 
end

We pass the formatter the list of columns to include in the table, and it writes the table to standard output.

The formatter doesn’t add any new project- or design-related techniques, so we’ll just list it.

project/4/issues/lib/issues/table_formatter.ex
 
defmodule​ Issues.TableFormatter ​do
 
 
import​ Enum, only: [ each: 2, map: 2, map_join: 3, ...

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