Skip to content

proposal: slices: function for count specific value on slice #62301

@dozheiny

Description

@dozheiny

The slices package has no functions for counting a specific value for now.
I think it's good the definition of function is like this:

func Counts[S []E, E comparable](s S, e E) int

An example of the Counts function is like this:

names := []string{"Alex", "Gopher", "Bob", "Alice", "Gopher"}
slices.Counts(names, "Gopher") // 2
slices.Counts(names, "Alex") // 1
slices.Counts(names, "James") // 0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Incoming

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions