Wonderful Learning Generator

From the time I started writing about Clojure, I had started using clojure-csv, one of the packages up on github.


(ns addr-verify
 (:gen-class)
 .
 .
 .
(:use clojure-csv.core)
)

clojure-csv/parse-csv returns a vector of vectors of strings. Each column in each row of the csv file being parsed is turned into a string. Each row is a vector, and each of those vectors is part of the outer enclosing vector.

A vector of vectors has turned out to be one of the best learning generators I have found. For example, what happens if your data has a null line? How do avoid processing it? What happens if one of the fields is blank? How do you get around that?


1,27 LILLIAN RD, ,E SOUTH HOOEY,ZA, ,11,14371,e,
1,254 FLORENCE AVE,,FARMVILLE HEIGHTS,ZA,02476,11,900036,e,
1,75 ZARATHON ST,,FARMVILLE HEIGHTS,ZA,02474,11,900037,e,
1,5 VIKING COURT,47,FARMVILLE HEIGHTS,ZA,02474,11,31879,e,
1,422 KNUCKLEHEAD RD,,NOWHERE,AZ,99999,11,999999999,e,
1,51 GROVE ST,DPW,FARMVILLE HEIGHTS,ZA,02476,11,923,e,
1,DPW,51 GROVE ST,FARMVILLE HEIGHTS,ZA,02474,11,924,e,
1,PD,112 MYSTIC ST,FARMVILLE HEIGHTS,ZA,02474,11,936,e,

Prior posts have examples on how to use parse-csv. I just wanted to emphasize that using a vector of vectors, no matter what generates it, can take you down a sometimes frustrating, but always fruitful learning path.

Advertisements

Leave a comment

Filed under Clojure

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s