Skip to content

Instantly share code, notes, and snippets.

@alces
Created November 29, 2017 11:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alces/fdb5a4fa68f697a08a2fd38dbfcef965 to your computer and use it in GitHub Desktop.
Save alces/fdb5a4fa68f697a08a2fd38dbfcef965 to your computer and use it in GitHub Desktop.
Adding Reduce method to List class
package main
import "container/list"
type MyList struct {
*list.List
}
func (l *MyList) Reduce(f func(interface{}, interface{}) interface{}) interface{} {
s := l.Front()
r := s.Value
for e := s.Next(); e != nil; e = e.Next() {
r = f(r, e.Value)
}
return r
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment