1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-11 00:02:28 +08:00

list: add sublist method (#49)

SubList returns a sub list of the original list between the specified fromIndex, inclusive, and toIndex, exclusive.
This commit is contained in:
donutloop
2022-07-23 09:00:04 +02:00
committed by GitHub
parent 741af66404
commit 0299c454ab
3 changed files with 53 additions and 0 deletions

View File

@@ -285,3 +285,11 @@ func (l *List[T]) Intersection(other *List[T]) *List[T] {
return result
}
// SubList returns a sub list of the original list between the specified fromIndex, inclusive, and toIndex, exclusive.
func (l *List[T]) SubList(fromIndex, toIndex int) *List[T] {
data := l.data[fromIndex:toIndex]
subList := make([]T, len(data))
copy(subList, data)
return NewList(subList)
}