// Extend behaves like Append, except it takes a single slice or array value // which will be concatenated to the named list. // // Unlike a variadic call to Append - which requires a []interface{} value - // Extend accepts slices or arrays of any type. // // Extend will panic if the given value is not a slice, array, or nil. func Extend(builder interface{}, name string, vs interface{}) interface{} { if vs == nil { return builder } maybeList, ok := getBuilderMap(builder).Lookup(name) var list ps.List if ok { list, ok = maybeList.(ps.List) } if !ok { list = ps.NewList() } forEach(vs, func(v interface{}) { list = list.Cons(v) }) return Set(builder, name, list) }
func listToSlice(list ps.List, arrayType reflect.Type) reflect.Value { size := list.Size() slice := reflect.MakeSlice(arrayType, size, size) for i := size - 1; i >= 0; i-- { val := reflect.ValueOf(list.Head()) slice.Index(i).Set(val) list = list.Tail() } return slice }