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

Task: Test the Comments

When I document my functions, I like to include examples of the function being used—comments saying things such as, “Feed it these arguments, and you’ll get this result.” In the Elixir world, a common way to do this is to show the function being used in an iex session.

Here’s an example. Our TableFormatter holds a number of self-contained functions that we can document.

project/5/issues/lib/issues/table_formatter.ex
 
defmodule​ Issues.TableFormatter ​do
 
 
import​ Enum, only: [ each: 2, map: 2, map_join: 3, max: 1 ]
 
 
@doc​ ​"""
 
Takes a list of row data, where each row is a HashDict, and a list of
 
headers. Prints a table to STDOUT of the data from each row
 
identified by each header. That is, each header ...

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