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

accessor not always "equivalent to calling Array.from" #206

Open
Fil opened this issue May 29, 2021 · 1 comment
Open

accessor not always "equivalent to calling Array.from" #206

Fil opened this issue May 29, 2021 · 1 comment
Labels
documentation Improvements or additions to docs

Comments

@Fil
Copy link
Member

Fil commented May 29, 2021

In the README we often have this sentence about the accessor to d3.extent and other reduction methods: "An optional accessor function may be specified, which is equivalent to calling Array.from before computing the extent."

However in most cases the accessor receives the original data as the third argument—whereas Array.from only sends (d, i) to its accessor.

Should we follow the README (and remove the third argument), or update this sentence in the README to be more accurate wrt the existing behavior? I'd vote for updating the README, maybe with the following sentence:

An optional accessor function may be specified, which receives the datum, the index, and the data, and returns the value.

@mbostock mbostock added the documentation Improvements or additions to docs label Jun 5, 2021
@mbostock
Copy link
Member

Another difference is that Array.from accepts values like {length: 42} whereas D3 only accepts values that are iterable. (This is why we do an explicit test for the Symbol.iterator method instead of calling Array.from directly in d3.map.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to docs
Development

No branches or pull requests

2 participants