github.com/primecitizens/pcz/std@v0.2.1/core/sys/envv.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright 2023 The Prime Citizens 3 4 //go:build !noos 5 6 package sys 7 8 import ( 9 "github.com/primecitizens/pcz/std/core/iter" 10 ) 11 12 func (it EnvIter) Nth(i int) (env string, ok bool) { 13 if it < 0 { 14 return 15 } 16 17 i, ok = iter.Index(i, len(envs)-int(it)) 18 if ok { 19 return nthenv(i), true 20 } 21 22 return 23 } 24 25 func (i EnvIter) Len() int { return len(envs) - int(i) } 26 27 func (i EnvIter) SliceFrom(start int) EnvIter { 28 start, ok := iter.Bound(start, len(envs)-int(i)) 29 if ok { 30 return i + EnvIter(start) 31 } 32 33 return EnvIter(len(envs)) 34 } 35 36 func (EnvIter) Less(i, j int) bool { return nthenv(i) < nthenv(j) } 37 func (EnvIter) Swap(i, j int) { envs[i], envs[j] = envs[j], envs[i] }