Skip to content

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

Open

Description

@Fil

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.

Activity

  1. mbostock commented on Aug 16, 2021

    @mbostock
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to docs

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions