github.com/searKing/golang/go@v1.2.74/container/slice/foreachordered.go (about) 1 // Copyright 2020 The searKing Author. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package slice 6 7 import ( 8 "github.com/searKing/golang/go/util/object" 9 ) 10 11 // ForEachOrderedFunc Performs an action for each element of this slice. 12 // <p>This operation processes the elements one at a time, in encounter 13 // order if one exists. Performing the action for one element 14 // performing the action for subsequent elements, but for any given element, 15 // the action may be performed in whatever thread the library chooses. 16 func ForEachOrderedFunc(s interface{}, f func(interface{})) { 17 forEachOrderedFunc(Of(s), f) 18 } 19 20 // forEachOrderedFunc is the same as ForEachOrderedFunc 21 func forEachOrderedFunc(s []interface{}, f func(interface{})) { 22 object.RequireNonNil(s, "forEachOrderedFunc called on nil slice") 23 object.RequireNonNil(f, "forEachOrderedFunc called on nil callfn") 24 25 for _, r := range s { 26 f(r) 27 } 28 return 29 }