Skip to content

Commit

Permalink
Merge pull request #133 from icey-yu/feat-map
Browse files Browse the repository at this point in the history
feat: map to slice
  • Loading branch information
icey-yu authored Sep 13, 2024
2 parents 6026390 + 2c306ef commit 9731939
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions utils/datautil/datautil.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,15 @@ func SliceSetAny[E any, K comparable](es []E, fn func(e E) K) map[K]struct{} {
})
}

// MapToSlice map to slice
func MapToSlice[E any, K comparable](m map[K]E, fn func(e E) K) []E {
es := make([]E, 0, len(m))
for _, v := range m {
es = append(es, v)
}
return es
}

func Filter[E, T any](es []E, fn func(e E) (T, bool)) []T {
rs := make([]T, 0, len(es))
for i := 0; i < len(es); i++ {
Expand Down

0 comments on commit 9731939

Please sign in to comment.