mirror of
https://github.com/samber/lo.git
synced 2026-04-23 07:49:50 +08:00
2.2 KiB
2.2 KiB
name, slug, sourceRef, category, subCategory, signatures, variantHelpers, similarHelpers, position
| name | slug | sourceRef | category | subCategory | signatures | variantHelpers | similarHelpers | position | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Reject | reject | it/seq.go#L586 | it | sequence |
|
|
|
180 |
Reject is the opposite of Filter, this method returns the elements of collection that predicate does not return true for.
collection := func(yield func(int) bool) {
yield(1)
yield(2)
yield(3)
yield(4)
}
filtered := it.Reject(collection, func(x int) bool {
return x%2 == 0
})
var result []int
for item := range filtered {
result = append(result, item)
}
// result contains [1, 3]
RejectI is the opposite of Filter, this method returns the elements of collection that predicate does not return true for, with index.
collection := func(yield func(string) bool) {
yield("a")
yield("b")
yield("c")
}
filtered := it.RejectI(collection, func(item string, index int) bool {
return index == 1
})
var result []string
for item := range filtered {
result = append(result, item)
}
// result contains ["a", "c"]
RejectMap returns a sequence obtained after both filtering and mapping using the given callback function. The callback function should return two values: the result of the mapping operation and whether the result element should be included or not.
collection := func(yield func(int) bool) {
yield(1)
yield(2)
yield(3)
yield(4)
}
filtered := it.RejectMap(collection, func(x int) (string, bool) {
return fmt.Sprintf("item-%d", x), x%2 == 0
})
var result []string
for item := range filtered {
result = append(result, item)
}
// result contains ["item-1", "item-3"]