Transformation: Take First n Items

Our next transformation is to extract the first count entries from the list. Resisting the temptation to write the function ourselves (How would you write such a function?), we discover the built-in Enum.take:

 def​ process({user, project, count}) ​do
  Issues.GithubIssues.fetch(user, project)
  |> decode_response()
  |> sort_into_descending_order()
» |> last(count)
 end
 
 def​ last(list, count) ​do
  list
  |> Enum.take(count)
  |> Enum.reverse
 end

Get Programming Elixir ≥ 1.6 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.