Skip to content

fix: normalise Keys/Values nil-vs-empty slice with Map #54

@millerjp

Description

@millerjp

Summary

Keys() and Values() return nil for an empty map (because append onto a nil slice stays nil). Map() returns an empty non-nil map. That asymmetry is observable (keys == nil is true for Keys but the same check on Map's return is false) and not documented.

Scope

Either:
A. Make Keys/Values return non-nil empty slices (make([]K, 0)) — consistent with Map's non-nil contract. Probably the right call since #TBD also pre-allocates.
B. Keep current behaviour but document explicitly.

Acceptance criteria

  1. TestKeys_Empty and TestValues_Empty assert non-nil slice (or explicitly nil — whichever is chosen).
  2. Godoc on all three methods consistent about nil-vs-empty return.

Source: code-reviewer + security-reviewer.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1Important, not blockingenhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions