d3-array icon indicating copy to clipboard operation
d3-array copied to clipboard

accessor not always "equivalent to calling Array.from"

Open Fil opened this issue 4 years ago • 1 comments

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.

Fil avatar May 29 '21 12:05 Fil

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.)

mbostock avatar Aug 16 '21 19:08 mbostock