SliceLength accepts any slice and returns a message if the length is not in the given range.
(min, max int)
| 38 | |
| 39 | // SliceLength accepts any slice and returns a message if the length is not in the given range. |
| 40 | func SliceLength[T any, V SliceType[T]](min, max int) func(s V) string { |
| 41 | return func(s V) string { |
| 42 | n := len(s) |
| 43 | |
| 44 | if min == max { |
| 45 | if n != min { |
| 46 | return fmt.Sprintf("must be %d elements", min) |
| 47 | } |
| 48 | |
| 49 | return "" |
| 50 | } |
| 51 | |
| 52 | if n < min || n > max { |
| 53 | return fmt.Sprintf("must be between %d and %d elements", min, max) |
| 54 | } |
| 55 | |
| 56 | return "" |
| 57 | } |
| 58 | } |
no outgoing calls
no test coverage detected
searching dependent graphs…