Exemplo n.º 1
0
// 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
}
Exemplo n.º 2
0
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
}