mirror of
https://github.com/samber/lo.git
synced 2025-12-24 12:48:02 +08:00
* lint: pin golangci-lint version * lint: fix issues triggered by go1.23 upgrade * feat: new iter package * lint: fix linter issues * fix: restore go1.18 * fix: rename package to "it" * feat: assign multiple sequences of maps * fix: panic in DropRight if n = 0 * docs: fix incorrect non-iter helper references * feat: implement Invert helper * feat: helpers for creating and checking empty sequences * feat: implement Reverse helper * feat: implement ReduceRight helper * feat: implement Shuffle helper * feat: implement Sample* helpers * refactor: rename helpers with Seq convention * feat: implement SeqToChannel2 helper * feat: implement HasPrefix/HasSuffix helpers * chore: port recent changes * perf: only iterate collection once in Every * refactor: reduce dupe code by reusing helpers internally * perf: reuse internal Mode slice * feat: implement Length helper * chore: duplicate unit tests for *I helpers * fix: omit duplicates in second Intersect list * feat: intersect more than 2 sequences * feat: implement Drain helper * feat: implement Seq/Seq2 conversion helpers * refactor: rename *Right* to *Last* * chore: minor cleanup * refactor: consistent predicate/transform parameter names * perf: abort Slice/Subset once upper bound reached * refactor: rename IsSortedByKey to IsSortedBy * refactor: reuse more helpers internally * feat: implement Cut* helpers * feat: implement Trim* helpers * perf: reduce allocations * docs: describe iteration and allocation expectations * Update .github/workflows/lint.yml --------- Co-authored-by: Samuel Berthe <dev@samuel-berthe.fr>
38 lines
618 B
Go
38 lines
618 B
Go
//go:build go1.23
|
|
|
|
package it
|
|
|
|
import (
|
|
"fmt"
|
|
"slices"
|
|
)
|
|
|
|
func ExampleWithoutBy() {
|
|
type User struct {
|
|
ID int
|
|
Name string
|
|
}
|
|
// original users
|
|
users := values(
|
|
User{ID: 1, Name: "Alice"},
|
|
User{ID: 2, Name: "Bob"},
|
|
User{ID: 3, Name: "Charlie"},
|
|
)
|
|
|
|
// exclude users with IDs 2 and 3
|
|
excludedIDs := []int{2, 3}
|
|
|
|
// extract function to get the user ID
|
|
extractID := func(user User) int {
|
|
return user.ID
|
|
}
|
|
|
|
// filtering users
|
|
filteredUsers := WithoutBy(users, extractID, excludedIDs...)
|
|
|
|
// output the filtered users
|
|
fmt.Printf("%v", slices.Collect(filteredUsers))
|
|
// Output:
|
|
// [{1 Alice}]
|
|
}
|