github.com/searKing/golang/go@v1.2.74/container/slice/skip.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 // SkipFunc returns a slice consisting of the remaining elements of this slice 12 // after discarding the first {@code n} elements of the slice. 13 // If this slice contains fewer than {@code n} elements then an 14 // empty slice will be returned. 15 func SkipFunc(s interface{}, n int) interface{} { 16 return normalizeSlice(skipFunc(Of(s), n), s) 17 } 18 19 // skipFunc is the same as SkipFunc. 20 func skipFunc(s []interface{}, n int) []interface{} { 21 object.RequireNonNil(s, "skipFunc called on nil slice") 22 m := len(s) 23 if m > n { 24 m = n 25 } 26 return s[m:] 27 }