示例#1
0
文件: Iter.go 项目: kenpusney/collect
func Reduce(iter collect.Iterator,
	fun func(*interface{}, interface{}),
	init interface{}) interface{} {
	for iter.HasNext() {
		fun(&init, iter.Next())
	}
	return init
}
示例#2
0
func Listify(it collect.Iterator) collect.List {
	list := &collect.LinkedList{}
	for it.HasNext() {
		list.Append(it.Next())
	}
	return list
	//return (algo.Reduce(it, func(list *interface{}, e interface{}) {
	//	((*list).(collect.List)).Append(e)
	//}, &collect.LinkedList{})).(collect.List)
}
示例#3
0
文件: Iter.go 项目: kenpusney/collect
func ForEach(iter collect.Iterator, fun func(interface{})) {
	for iter.HasNext() {
		fun(iter.Next())
	}
}