Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Iterator interface #17

Closed
superbobry opened this issue Aug 22, 2016 · 2 comments
Closed

Iterator interface #17

superbobry opened this issue Aug 22, 2016 · 2 comments

Comments

@superbobry
Copy link

Have you considered complementing parse and parseRows with iterator-based versions? This might be useful e.g. if one only needs to sumarise the data.

@mbostock
Copy link
Member

You can achieve similar functionality by passing a row conversion function that returns null or undefined. For example using d3.csvParse:

var sum = 0;
d3.csvParse(csv, function(d) {
  sum += +d.foo;
});
console.log("sum", sum);

Or using d3.csv:

var sum = 0;
d3.csv("numbers.csv", function(d) {
  sum += +d.foo;
}, function(error) {
  if (error) throw error;
  console.log("sum", sum);
});

A proper iterator might be nice, but I don’t feel like it’s urgent to provide an alternative API at this point. Although it might be nice when we can require that native ES collections/iterables and for…of loops are available.

@superbobry
Copy link
Author

I see, thank you very much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants