Why I’m going with more maps the next time

I have wondered why I had seen comments that indicated using Clojure vectors and nth good “make a stink” (paraphrased). nth used with vectors is very useful for some operations, but I know realize why accessing vectors this way can be a problem.

I’ve written a small Clojure program that pulls apart a .csv file using clojure-csv. This program uses indexes. The problem is, I thought I would extract only the columns I needed, process the data, and then write out the results. It has resulted in a blur of indexes.

To set the type of application, it is comparing whether a health insurance subscriber is in the town’s application appears in the vendor’s application. It also determines the reverse, which is whether or not every subscriber in the vendor’s application also shows up in the town’s application.

At some point I’ll rewrite this program using zip-map, because each report comes with column names as the first row. What could be better? Then I can access any column I want by name, and not guess the column arrangement of a vector of data.

Advertisements

3 Comments

Filed under Clojure

3 responses to “Why I’m going with more maps the next time

  1. sb

    A lot of times destructuring provides an even cleaner solution (remember, you can ignore slots with _).

    • Octopusgrabbus

      Thanks. This was a helpful answer. I keep forgetting that destructuring will provide a similar facility to mapping.

      • Miloslav Rauš

        I’d go with destructuring only if I’d be sure the structure will remain the same. When you read the column names from first row, you have the benefit that the columns can shift around and your code won’t notice 😉

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