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: MoreCoolStuff-1

    Write a sigil ~v that parses multiple lines of comma-separated data, returning a list where each element is a row of data and each row is a list of values. Don’t worry about quoting—just assume each field is separated by a comma.

     
    csv = ~v​"""
     
    1,2,3
     
    cat,dog
     
    """

    would generate [["1","2","3"], ["cat","dog"]].

  • Exercise: MoreCoolStuff-2

    The function Float.parse converts leading characters of a string to a float, returning either a tuple containing the value and the rest of the string, or the atom :error.

    Update your CSV sigil so that numbers are automatically converted.

     
    csv = ~v​"""
     
    1,2,3.14
     
    cat,dog
     
    """

    should generate [[1.0,2.0,3.14], ["cat","dog"]].

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