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-5

    Implement the following Enum functions using no library functions or list comprehensions: all?, each, filter, split, and take. You may need to use an if statement to implement filter. The syntax for this is

     
    if​ condition ​do
     
    expression(s)
     
    else
     
    expression(s)
     
    end
  • Exercise: ListsAndRecursion-6

    (Hard) Write a flatten(list) function that takes a list that may contain any number of sublists, which themselves may contain sublists, to any depth. It returns the elements of these lists as a flat list.

     
    iex>​ MyList.flatten([ 1, [ 2, 3, [4] ], 5, [[[6]]]])
     
    [1,2,3,4,5,6]

    Hint: You may have to use Enum.reverse to get your result in the correct order.

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