Skip to content

proposal: x/exp/slices: add Set #57241

@k-x7

Description

@k-x7

Add a new function, slices.Set which removes all duplicate elements in a slice.

Proposed Signature:

func Set[E comparable](s []E)

Usage:

i := []int{1, 2, 3, 1, 2, 3, 1, 4, 5, 6, 2, 1, 1, 2, 4, 7}
slices.Set(i) // i == []int{6, 3, 2, 4, 7, 1, 5} or i == []int{1, 2, 3, 4, 5, 6, 7}

The name slices.Set from the data type Set, which holds unique values, without any particular order, slices.Set might be confusing as a function name, other alternative is slices.Unique.

Examples where people asked for slimier function: 1, 2, 3

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions