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:
@@ -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]]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user