I finally got the main logic of the working with this code.
|> DataMorph.structs_from_csv("open-register", :iso_country) \
|> Enum.map(fn(x) -> inspect(x, [limit: :infinity])<>",\n" end) \
Each line is appended with a comma. What I want to do now is to add an opening bracket for the list
[, ignore the comma on the last item
, and add the closing bracket `]’.
1. if it is the first item prepend the '['.
2. output the item
3. if is not the last item append a `,`
4. if all have been added, append the closing `]`.
How can I do that in snazzy one-liner. In the same pipelined set of functions. I want to do it in a more
functional style , not I would normally do it in procedural languages.
The normal way is to ascertain the size of the list, set a variable to the no of items processed, if 0 items, prepend the
[, print the item, increment the printed count, if not same as no of items, append the the
, , of the last tiem append the closing bracket. This approach can be prone to off by one errors, which is why I want to try a more functional style.