Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "errors"
- "github.com/cwchentw/algo-golang/list"
- "log"
- )
- func main() {
- l := list.New()
- for i := 1; i <= 10; i++ {
- l.Push(i)
- }
- evens, _ := l.Select(isEven)
- for e := range evens.Iter() {
- n, _ := e.(int)
- if n % 2 != 0 {
- log.Fatalln("Error Select result")
- }
- }
- }
- func isEven(a interface{}) (bool, error) {
- n, ok := a.(int)
- if ok != true {
- return false, errors.New("Failed type assertion on a")
- }
- return n % 2 == 0, nil
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement