mirror of
https://github.com/samber/lo.git
synced 2026-04-22 23:47:11 +08:00
32 lines
621 B
Markdown
32 lines
621 B
Markdown
---
|
|
name: TrimPrefix
|
|
slug: trimprefix
|
|
sourceRef: it/seq.go#L778
|
|
category: it
|
|
subCategory: string
|
|
signatures:
|
|
- "func TrimPrefix[T comparable, I ~func(func(T) bool)](collection I, prefix []T) I"
|
|
variantHelpers: []
|
|
similarHelpers:
|
|
- core#string#trimprefix
|
|
position: 265
|
|
---
|
|
|
|
TrimPrefix removes all the leading prefix from the collection.
|
|
|
|
```go
|
|
collection := func(yield func(int) bool) {
|
|
yield(1)
|
|
yield(2)
|
|
yield(1)
|
|
yield(2)
|
|
yield(3)
|
|
}
|
|
|
|
trimmed := it.TrimPrefix(collection, []int{1, 2})
|
|
var result []int
|
|
for item := range trimmed {
|
|
result = append(result, item)
|
|
}
|
|
// result contains [1, 2, 3]
|
|
``` |