Skip to content

Documentation for HashMap's FromIterator with duplicate keys in the iterator #110260

Open
@jrose-signal

Description

@jrose-signal

Location

HashMap

Summary

HashMap implements FromIterator and Extend, but does not document what happens if there are duplicate keys in the iterator. The documentation for Extend does say "When extending a collection with an already existing key, that entry is updated", but

  1. that isn't visible anywhere on the HashMap page,
  2. FromIterator doesn't have to be implemented using Extend (though HashMap's is), and
  3. that still doesn't specify behavior for duplicate keys in the iterator itself.

The current implementation silently takes the last value in the iterator, which is useful behavior and could easily be justified by saying "collection.extend(a).extend(b) should always be equivalent to collection.extend(a.chain(b))", but technically that isn't written down anywhere.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsA-iteratorsArea: IteratorsT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions