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`.
20 lines
425 B
Go
20 lines
425 B
Go
package underscore_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
u "github.com/rjNemo/underscore"
|
|
)
|
|
|
|
func TestUniqueBy(t *testing.T) {
|
|
type user struct {
|
|
ID int
|
|
Email string
|
|
}
|
|
in := []user{{1, "a@x"}, {2, "b@x"}, {3, "a@x"}, {4, "c@x"}, {5, "b@x"}}
|
|
out := u.UniqueBy(in, func(u user) string { return u.Email })
|
|
want := []user{{1, "a@x"}, {2, "b@x"}, {4, "c@x"}}
|
|
assert.Equal(t, want, out)
|
|
}
|