go_goutils/checks/checks.go

68 lines
1.6 KiB
Go

/*
GoUtils - a library to assist with various Golang-related functions
Copyright (C) 2020 Brent Saner
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package checks
func All(l []interface{}) (int, bool) {
for idx, i := range l {
switch i.(type) {
case bool:
if i == false {
return idx, false
}
case string:
if i == "" {
return idx, false
}
case int8, int16, int32, int64, uint8, uint16, uint32, uint64, uintptr, float32, float64:
if i == 0 {
return idx, false
}
default:
if i == nil {
return idx, false
}
}
}
return 0, true
}
func Any(l []interface{}) (int, bool) {
for idx, i := range l {
switch i.(type) {
case bool:
if i == true {
return idx, true
}
case string:
if i != "" {
return idx, true
}
case int8, int16, int32, int64, uint8, uint16, uint32, uint64, uintptr, float32, float64:
if i != 0 {
return idx, true
}
default:
if i != nil {
return idx, true
}
}
}
return 0, false
}