1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-06 21:52: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

@@ -46,6 +46,7 @@ import (
- [Unique](#Unique)
- [Union](#Union)
- [Intersection](#Intersection)
- [SubList](#SubList)
<div STYLE="page-break-after: always;"></div>
@@ -791,4 +792,32 @@ func main() {
fmt.Println(li3.Data()) //4
}
```
### <span id="SubList">SubList</span>
<p>SubList returns a sub list of the original list between the specified fromIndex, inclusive, and toIndex, exclusive.</p>
<b>Signature:</b>
```go
func (l *List[T]) SubList(fromIndex, toIndex int) *List[T]
```
<b>Example:</b>
```go
package main
import (
"fmt"
list "github.com/duke-git/lancet/v2/datastructure/list"
)
func main() {
l := list.NewList([]int{1, 2, 3, 4, 5, 6})
fmt.Println(l.SubList(2, 5)) // []int{3, 4, 5}
}
```