-
Notifications
You must be signed in to change notification settings - Fork 12
/
peek.go
28 lines (22 loc) · 804 Bytes
/
peek.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// Copyright 2020 The searKing Author. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package slice
import (
"github.com/searKing/golang/go/util/object"
)
// PeekFunc returns a slice consisting of the elements of this slice, additionally
// performing the provided action on each element as elements are consumed
// from the resulting slice.
func PeekFunc(s interface{}, f func(interface{})) interface{} {
return normalizeSlice(peekFunc(Of(s), f), s)
}
// peekFunc is the same as PeekFunc.
func peekFunc(s []interface{}, f func(interface{})) []interface{} {
object.RequireNonNil(s, "peekFunc called on nil slice")
object.RequireNonNil(f, "peekFunc called on nil callfn")
for _, r := range s {
f(r)
}
return s
}