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

Your Turn

  • Exercise: ListsAndRecursion-1

    Write a mapsum function that takes a list and a function. It applies the function to each element of the list and then sums the result, so

     
    iex>​ MyList.mapsum [1, 2, 3], &(&1 * &1)
     
    14
  • Exercise: ListsAndRecursion-2

    Write a max(list) that returns the element with the maximum value in the list. (This is slightly trickier than it sounds.)

  • Exercise: ListsAndRecursion-3

    An Elixir single-quoted string is actually a list of individual character codes. Write a caesar(list, n) function that adds n to each list element, wrapping if the addition results in a character greater than z.

     
    iex>​ MyList.caesar(​'ryvkve'​, 13)
     
    ?????? :)

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