mbostock/d3 — pull request #1028 by smcgivern (2013-01-26 11:18:37+00:00)
Title: Allow type conversion in dsv.parse

This is a stab at addressing #387, by adding an optional `types` argument to `dsv.parse`, which can either be an array or an object depending on whether the functions in `types` should be applied by position or name. (Although if you want to do the former, it seems better to just use `dsv.parseRows` directly.)

Problems:

1. `dsv.parse` was optimized in 2358fd0fb43d74cb72ddc4dd2218ab9153d0af02; this makes it slower again, even when the type conversion isn't used. I have created a [basic benchmark](https://gist.github.com/02033970558429c73626) for the behaviour using this function before optimization, after optimization, and after this change.
2. The interface may not be ideal. For numbers, I have been using `parseInt` and `parseFloat`, which could be wrapped as something like `d3.csv.int`, but then that's no shorter. For dates and times, `d3.time.format` already seems perfect to me.
3. As a corollary, because this accepts functions, it isn't restricted to just converting types. That seems like a duplication of effort, given that this is adding another layer of indirection: it calls another function from within `o`, which in turn calls the functions passed in `types`, and the only reason for not using `dsv.parseRows` is convenience. It's also possible for people to do unexpected things with it.
4. There is no type inference, which is mentioned in passing in the original issue.