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

feat: add Partition for slice

This commit is contained in:
dudaodong
2023-09-04 11:30:50 +08:00
parent 4037b96cc4
commit 541e6d4ea3
3 changed files with 59 additions and 2 deletions

View File

@@ -1046,3 +1046,20 @@ func ExampleJoin() {
// 1,2,3,4,5
// 1-2-3-4-5
}
func ExamplePartition() {
nums := []int{1, 2, 3, 4, 5}
result1 := Partition(nums)
result2 := Partition(nums, func(n int) bool { return n%2 == 0 })
result3 := Partition(nums, func(n int) bool { return n == 1 || n == 2 }, func(n int) bool { return n == 2 || n == 3 || n == 4 })
fmt.Println(result1)
fmt.Println(result2)
fmt.Println(result3)
// Output:
// [[1 2 3 4 5]]
// [[2 4] [1 3 5]]
// [[1 2] [3 4] [5]]
}