예제 #1
0
파일: metrics.go 프로젝트: hrhelena/scope
// revCons appends acc to the head of curr, where acc is in reverse order.
// acc must never be nil, curr can be.
func revCons(acc, curr ps.List) ps.List {
	if curr == nil {
		return acc.Reverse()
	}
	for !acc.IsNil() {
		acc, curr = acc.Tail(), curr.Cons(acc.Head())
	}
	return curr
}
예제 #2
0
// 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)
}