go-func/stream/reduce.go

10 lines
290 B
Go
Raw Normal View History

2017-07-14 20:42:20 +08:00
package stream
//Reduce 对任意数组操作,对数组进行降维打击
func (s *Stream) Reduce(identity interface{}, accumulator func(interface{}, interface{}) interface{}) interface{} {
for _, v := range s.list {
identity = accumulator(identity, v)
}
return identity
}