mirror of
https://github.com/rjNemo/underscore
synced 2026-06-06 10:36:43 +00:00
- Add `Chunk` to split slices into groups of size n. - Add `ContainsBy` for predicate-based containment checks. - Add `UniqueBy` to deduplicate slices by key selector. - Add `ParallelMap` for concurrent mapping with context and error handling. - Add `maps.Keys` and `maps.Values` helpers for extracting map keys/values. - Update README and docs for new features. - Refactor `Contains` to use `slices.Contains`.
16 lines
358 B
Go
16 lines
358 B
Go
package maps
|
|
|
|
import "maps"
|
|
|
|
type M[K comparable, V any] map[K]V
|
|
|
|
// Map produces a new slice of values by mapping each value in the slice through
|
|
// a transform function.
|
|
func Map[K, Q comparable, V, W any](m M[K, V], f func(K, V) M[Q, W]) M[Q, W] {
|
|
res := make(M[Q, W], len(m))
|
|
for k, v := range m {
|
|
mm := f(k, v)
|
|
maps.Copy(res, mm)
|
|
}
|
|
return res
|
|
}
|