mirror of
https://github.com/rjNemo/underscore
synced 2026-06-06 02:26:42 +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`.
487 B
487 B
| title | date |
|---|---|
| ParallelMap | 2025-09-01T00:00:00-00:00 |
ParallelMap applies a function to each element concurrently using a worker pool,
preserves order, and supports context cancellation.
package main
import (
"context"
"fmt"
u "github.com/rjNemo/underscore"
)
func main() {
out, err := u.ParallelMap(context.Background(),
[]int{1,2,3,4}, 4, func(ctx context.Context, n int) (int, error) {
return n*n, nil
})
fmt.Println(out, err) // [1 4 9 16] <nil>
}