Skip to content

proposal: slice/list/map should support more operators, such as in, not in. #53067

Closed
@yuezhongtao

Description

@yuezhongtao

The current operation of built-in container types is not elegant enough. The scenarios are as follows.

  1. To determine whether an element exists in the list/slice, we need to traverse the list/slice in the business code
  2. To get the map key value set, you need to traverse the entire map in the business code
  3. Judging whether the map contains key values is not elegant enough

The solution is as follows:

  1. slice/list/map supports in and not in operators.
s := []string{"e1"}
if "e1" in s {
  //todo
}
if "e2" not in s {
  //todo
}
  1. Map supports Keys(), Values() operations
m := make(map[string]string)
keys := m.Keys()
vals := m.Values()

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions