Last active
November 27, 2017 14:12
-
-
Save alces/4b36d9d2e581215ad0951478dd812123 to your computer and use it in GitHub Desktop.
Adding Filter method to List
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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