Skip to content

Commit 5fb5516

Browse files
committed
update doc
1 parent 04a1ee4 commit 5fb5516

File tree

3 files changed

+38
-40
lines changed

3 files changed

+38
-40
lines changed

gs/README.md

+17-18
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ index5 := gs.LastIndexOf(list, 5)
9898
Determines whether all the members of a slice satisfy the specified test.
9999

100100
```go
101-
allless4 := gs.Every([]int{1, 2, 3}, func(t, i int) bool {
102-
return t < 4
101+
allless4 := gs.Every([]int{1, 2, 3}, func(item, index int) bool {
102+
return item < 4
103103
})
104104
// true
105105
```
@@ -109,8 +109,8 @@ allless4 := gs.Every([]int{1, 2, 3}, func(t, i int) bool {
109109
Determines whether the specified callback function returns true for any element of a slice.
110110

111111
```go
112-
hasEven := gs.Some([]int{5, 6, 7}, func(t, i int) bool {
113-
return t%2 == 0
112+
hasEven := gs.Some([]int{5, 6, 7}, func(item, index int) bool {
113+
return item%2 == 0
114114
})
115115
// true
116116
```
@@ -120,19 +120,18 @@ hasEven := gs.Some([]int{5, 6, 7}, func(t, i int) bool {
120120
Performs the specified action for each element in a slice.
121121

122122
```go
123-
gs.ForEach([]int{1, 2, 3}, func(t int, i int) {
124-
println(t)
123+
gs.ForEach([]int{1, 2, 3}, func(item, index int) {
124+
println(item)
125125
})
126-
127126
```
128127

129128
### Map
130129

131130
Calls a defined callback function on each element of a slice, and returns a slice that contains the results.
132131

133132
```go
134-
list := gs.Map([]int{5, 6, 7}, func(t int, i int) string {
135-
return strconv.Itoa(t)
133+
list := gs.Map([]int{5, 6, 7}, func(item, index int) string {
134+
return strconv.Itoa(item)
136135
})
137136
// ["5" "6" "7"]
138137
```
@@ -142,8 +141,8 @@ list := gs.Map([]int{5, 6, 7}, func(t int, i int) string {
142141
Returns the elements of a slice that meet the condition specified in a callback function.
143142

144143
```go
145-
list = gs.Filter([]int{1, 2, 3, 4, 5, 6, 7, 8}, func(t, i int) bool {
146-
return t%2 == 0
144+
list = gs.Filter([]int{1, 2, 3, 4, 5, 6, 7, 8}, func(item, index int) bool {
145+
return item%2 == 0
147146
})
148147
// [2 4 6 8]
149148
```
@@ -153,8 +152,8 @@ list = gs.Filter([]int{1, 2, 3, 4, 5, 6, 7, 8}, func(t, i int) bool {
153152
Calls the specified callback function for all the elements in a slice. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
154153

155154
```go
156-
sum := gs.Reduce([]int{1, 2, 3}, func(r int, t int, i int) int {
157-
return r + t
155+
sum := gs.Reduce([]int{1, 2, 3}, func(previousValue int, currentValue int, currentIndex int) int {
156+
return previousValue + currentValue
158157
}, 0)
159158
// 6
160159
```
@@ -164,8 +163,8 @@ sum := gs.Reduce([]int{1, 2, 3}, func(r int, t int, i int) int {
164163
Returns the index of the first element in the slice that satisfies the provided testing function. Otherwise, it returns -1
165164

166165
```go
167-
index := gs.FindIndex([]int{1, 2, 3}, func(t, i int) bool {
168-
return t%2 == 0
166+
index := gs.FindIndex([]int{1, 2, 3}, func(item, index int) bool {
167+
return item%2 == 0
169168
})
170169
// 1
171170
```
@@ -175,12 +174,12 @@ index := gs.FindIndex([]int{1, 2, 3}, func(t, i int) bool {
175174
Returns the value of the first element in the provided slice that satisfies the provided testing function.
176175

177176
```go
178-
item, err := gs.Find([]int{1, 2, 3}, func(t, i int) bool {
179-
return t%2 == 0
177+
target, err := gs.Find([]int{1, 2, 3}, func(item, index int) bool {
178+
return item%2 == 0
180179
})
181180

182181
if err != nil {
183-
println(item)
182+
println(target)
184183
// 2
185184
}
186185
```

gs/README.zh-CN.md

+17-18
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ index5 := gs.LastIndexOf(list, 5)
9898
测试一个 `slice` 内的所有元素是否都能通过某个指定函数的测试。
9999

100100
```go
101-
allless4 := gs.Every([]int{1, 2, 3}, func(t, i int) bool {
102-
return t < 4
101+
allless4 := gs.Every([]int{1, 2, 3}, func(item, index int) bool {
102+
return item < 4
103103
})
104104
// true
105105
```
@@ -109,8 +109,8 @@ allless4 := gs.Every([]int{1, 2, 3}, func(t, i int) bool {
109109
测试 `slice` 中是不是至少有 1 个元素通过了被提供的函数测试。
110110

111111
```go
112-
hasEven := gs.Some([]int{5, 6, 7}, func(t, i int) bool {
113-
return t%2 == 0
112+
hasEven := gs.Some([]int{5, 6, 7}, func(item, index int) bool {
113+
return item%2 == 0
114114
})
115115
// true
116116
```
@@ -120,19 +120,18 @@ hasEven := gs.Some([]int{5, 6, 7}, func(t, i int) bool {
120120
`slice` 的每个元素执行一次给定的函数。
121121

122122
```go
123-
gs.ForEach([]int{1, 2, 3}, func(t int, i int) {
124-
println(t)
123+
gs.ForEach([]int{1, 2, 3}, func(item, index int) {
124+
println(item)
125125
})
126-
127126
```
128127

129128
### Map
130129

131130
创建一个新 `slice` ,其结果是该 `slice` 中的每个元素是调用一次提供的函数后的返回值。
132131

133132
```go
134-
list := gs.Map([]int{5, 6, 7}, func(t int, i int) string {
135-
return strconv.Itoa(t)
133+
list := gs.Map([]int{5, 6, 7}, func(item, index int) string {
134+
return strconv.Itoa(item)
136135
})
137136
// ["5" "6" "7"]
138137
```
@@ -142,8 +141,8 @@ list := gs.Map([]int{5, 6, 7}, func(t int, i int) string {
142141
创建一个新 `slice` , 其包含通过所提供函数实现的测试的所有元素。
143142

144143
```go
145-
list = gs.Filter([]int{1, 2, 3, 4, 5, 6, 7, 8}, func(t, i int) bool {
146-
return t%2 == 0
144+
list = gs.Filter([]int{1, 2, 3, 4, 5, 6, 7, 8}, func(item, index int) bool {
145+
return item%2 == 0
147146
})
148147
// [2 4 6 8]
149148
```
@@ -153,8 +152,8 @@ list = gs.Filter([]int{1, 2, 3, 4, 5, 6, 7, 8}, func(t, i int) bool {
153152
`slice` 中的每个元素执行一个由您提供的 reducer 函数(升序执行),将其结果汇总为单个返回值。
154153

155154
```go
156-
sum := gs.Reduce([]int{1, 2, 3}, func(r int, t int, i int) int {
157-
return r + t
155+
sum := gs.Reduce([]int{1, 2, 3}, func(previousValue int, currentValue int, currentIndex int) int {
156+
return previousValue + currentValue
158157
}, 0)
159158
// 6
160159
```
@@ -164,8 +163,8 @@ sum := gs.Reduce([]int{1, 2, 3}, func(r int, t int, i int) int {
164163
返回 `slice` 中满足提供的测试函数的第一个元素的索引。若没有找到对应元素则返回-1。
165164

166165
```go
167-
index := gs.FindIndex([]int{1, 2, 3}, func(t, i int) bool {
168-
return t%2 == 0
166+
index := gs.FindIndex([]int{1, 2, 3}, func(item, index int) bool {
167+
return item%2 == 0
169168
})
170169
// 1
171170
```
@@ -175,12 +174,12 @@ index := gs.FindIndex([]int{1, 2, 3}, func(t, i int) bool {
175174
返回 `slice` 中满足提供的测试函数的第一个元素的值。
176175

177176
```go
178-
item, err := gs.Find([]int{1, 2, 3}, func(t, i int) bool {
179-
return t%2 == 0
177+
target, err := gs.Find([]int{1, 2, 3}, func(item, index int) bool {
178+
return item%2 == 0
180179
})
181180

182181
if err != nil {
183-
println(item)
182+
println(target)
184183
// 2
185184
}
186185
```

gs/gs_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,14 @@ func TestEvery(t *testing.T) {
6262
list := []int{1, 2, 3}
6363

6464
assert.True(
65-
Every(list, func(t, i int) bool {
66-
return t < 4
65+
Every(list, func(item, index int) bool {
66+
return item < 4
6767
}),
6868
)
6969

7070
assert.False(
71-
Every(list, func(t, i int) bool {
72-
return t < 3
71+
Every(list, func(item, index int) bool {
72+
return item < 3
7373
}),
7474
)
7575
}

0 commit comments

Comments
 (0)