GoCollections/main.go

37 lines
855 B
Go
Raw Normal View History

2021-05-20 17:32:35 +08:00
package main
import (
"fmt"
2021-05-21 09:48:33 +08:00
"github.com/tursom/GoCollections/collections"
"github.com/tursom/GoCollections/exceptions"
2021-05-20 17:32:35 +08:00
)
func main() {
2021-05-21 16:57:33 +08:00
_, err := exceptions.Try(func() (interface{}, exceptions.Exception) {
2021-05-21 09:41:58 +08:00
panic("test")
2021-05-21 16:57:33 +08:00
}, func(r interface{}) (interface{}, exceptions.Exception) {
2021-05-21 09:41:58 +08:00
fmt.Println("recover from panic", r)
2021-05-21 10:31:49 +08:00
return nil, exceptions.NewIndexOutOfBound(fmt.Sprint(r), true)
})
2021-05-21 16:57:33 +08:00
exceptions.Print(err)
2021-05-21 09:41:58 +08:00
2021-05-21 23:07:48 +08:00
list := collections.NewConcurrentLinkedQueue()
2021-05-20 17:32:35 +08:00
fmt.Println(list)
for i := 0; i < 20; i++ {
2021-05-21 23:07:48 +08:00
list.Push(i)
fmt.Println(list)
2021-05-20 17:32:35 +08:00
}
2021-05-21 16:57:33 +08:00
_ = collections.LoopMutable(list, func(element interface{}, iterator collections.MutableIterator) (err exceptions.Exception) {
2021-05-20 17:32:35 +08:00
if element.(int)&1 == 0 {
2021-05-21 10:31:49 +08:00
err = iterator.Remove()
2021-05-20 17:32:35 +08:00
}
fmt.Println(list)
2021-05-21 10:31:49 +08:00
return
2021-05-20 17:32:35 +08:00
})
//for i := 0; i < 10; i++ {
// list.Remove(i * 2)
// fmt.Println(list)
//}
}