Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Excerpt
- // Select items from the list when item fulfill the predicate.
- // Implement grep function object to use this method.
- func (list *List) Select(grep func(interface{}) (bool, error)) (*List, error) {
- newList := New()
- current := list.head
- for current != nil {
- b, err := grep(current.data)
- if err != nil {
- return newList, err
- }
- if b == true {
- newList.Push(current.data)
- }
- current = current.next
- }
- return newList, nil
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement