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"]].
- Exercise: MoreCoolStuff-3
(Hard) Sometimes ...
Get Programming Elixir 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.