github.com/searKing/golang/go@v1.2.74/container/slice/dropwhile.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 // DropWhileFunc returns, if this slice is ordered, a slice consisting of the remaining 12 // elements of this slice after dropping the longest prefix of elements 13 // that match the given predicate. Otherwise returns, if this slice is 14 // unordered, a slice consisting of the remaining elements of this slice 15 // after dropping a subset of elements that match the given predicate. 16 func DropWhileFunc(s interface{}, f func(interface{}) bool) interface{} { 17 return normalizeSlice(dropWhileFunc(Of(s), f, true), s) 18 } 19 20 // dropWhileFunc is the same as DropWhileFunc. 21 func dropWhileFunc(s []interface{}, f func(interface{}) bool, truth bool) []interface{} { 22 object.RequireNonNil(s, "dropWhileFunc called on nil slice") 23 object.RequireNonNil(f, "dropWhileFunc called on nil callfn") 24 25 var sTaken = []interface{}{} 26 dropFound := false 27 for _, r := range s { 28 if !dropFound && f(r) == truth { 29 continue 30 } 31 dropFound = true 32 sTaken = append(sTaken, r) 33 } 34 return sTaken 35 }