summaryrefslogtreecommitdiffstats
path: root/cmd/jp/split.go
blob: 4f36825c961fcea35985e2bfe4d7f521c4642764 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
package main

import "reflect"

func flatten(in [][]reflect.Value) (out []reflect.Value) {
	for _, a := range in {
		for i := range a {
			out = append(out, a[i])
		}
	}
	return
}

func split(in [][]reflect.Value) (x, y [][]reflect.Value) {
	flat := flatten(in)
	n := len(flat)
	x = [][]reflect.Value{flat[:n/2]}
	y = [][]reflect.Value{flat[n/2:]}
	return
}