Skip to content

Instantly share code, notes, and snippets.

@alces
Last active November 27, 2017 14:12
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/4b36d9d2e581215ad0951478dd812123 to your computer and use it in GitHub Desktop.
Save alces/4b36d9d2e581215ad0951478dd812123 to your computer and use it in GitHub Desktop.
Adding Filter method to List
package main
import "container/list"
type MyList struct {
*list.List
}
func (l *MyList) Filter(f func(interface{}) bool) *MyList {
nl := &MyList{list.New()}
for e := l.Front(); e != nil; e = e.Next() {
v := e.Value
if f(v) {
nl.PushBack(v)
}
}
return nl
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment