Closed
Description
The current operation of built-in container types is not elegant enough. The scenarios are as follows.
- To determine whether an element exists in the list/slice, we need to traverse the list/slice in the business code
- To get the map key value set, you need to traverse the entire map in the business code
- Judging whether the map contains key values is not elegant enough
The solution is as follows:
- slice/list/map supports in and not in operators.
s := []string{"e1"}
if "e1" in s {
//todo
}
if "e2" not in s {
//todo
}
- Map supports Keys(), Values() operations
m := make(map[string]string)
keys := m.Keys()
vals := m.Values()