I have been tasked to design and build a module/function that parses
a CSV file and applies a 2-arity Fun, record by record. I don’t really know where to start, as I have never done this before.
I normally just use the phoenix command, and libraries to handle any sort of Parser. Any ideas as to where i could start, or perhaps a guide that I can follow along?
Personally I feel like the imposter Syndrome is kicking in, because it seems so hard for somehting to simple. As a newer Elixir developer this is a bit challenging.
In essence I am to loop through the arrays and separate the commas and reprint the array?
Also what is meant by “applies a 2-arity Fun” It takes two arguments if one argument is a CSV file whats the other one and array?
@Davy_Jones_Locker The best way to start working on a problem where you don’t know the answer is to break it down into pieces, and work on each piece one at a time. To “Parse a CSV” file you need to:
Read a file into a string
Split that string by line into a list of strings
Split each line by commas (roughly).
So let’s start with (1) and (2). Are you able to get a file read into a string? Have you tried splitting that string into lines?
One age old way to write a parser by hand is recursive decent And it maps really well to the concept of functional programming. It will be a bit more involved than using String.split etc but you can handle string escape rule, potential comments, and more.