summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSergey Grebenshchikov <sgreben@gmail.com>2018-06-17 16:01:57 +0200
committerSergey Grebenshchikov <sgreben@gmail.com>2018-06-17 16:01:57 +0200
commit24e934443db4773b7ec06b7bf1d30ff2ae22685b (patch)
tree0452008e1e0ef23730c289d83b351bc63bc02736
parent6d38b596f52f526f245a07de803109e5a6e0117c (diff)
Skip invalid values in flatten()
-rw-r--r--cmd/jp/split.go11
1 files changed, 6 insertions, 5 deletions
diff --git a/cmd/jp/split.go b/cmd/jp/split.go
index acca93c..2220c37 100644
--- a/cmd/jp/split.go
+++ b/cmd/jp/split.go
@@ -1,8 +1,6 @@
package main
-import (
- "reflect"
-)
+import "reflect"
var indexableKind = map[reflect.Kind]bool{
reflect.Slice: true,
@@ -12,15 +10,18 @@ var indexableKind = map[reflect.Kind]bool{
func flatten(in [][]reflect.Value) (out []reflect.Value) {
for _, a := range in {
for _, v := range a {
+ if !v.IsValid() {
+ continue
+ }
if indexableKind[v.Kind()] {
sub := make([]reflect.Value, v.Len())
for j := 0; j < v.Len(); j++ {
- sub = append(sub, v.Index((j)))
+ sub = append(sub, v.Index(j))
}
out = append(out, flatten([][]reflect.Value{sub})...)
continue
}
- if v.IsValid() && v.CanInterface() {
+ if v.CanInterface() {
if sub, ok := v.Interface().([]interface{}); ok {
for i := range sub {
out = append(out, reflect.ValueOf(sub[i]))