github.com/searKing/golang/go@v1.2.74/exp/container/queue/example_test.go (about) 1 // Copyright 2022 The searKing Author. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package queue_test 6 7 import ( 8 "fmt" 9 10 "github.com/searKing/golang/go/exp/container/queue" 11 ) 12 13 func Example() { 14 // Create a new list and put some numbers in it. 15 l := queue.New[int]() 16 l.PushBack(1) 17 l.PushBack(2) 18 l.PushBack(3) 19 l.PushBack(4) 20 21 l2 := queue.New[int]() 22 l2.PushBack(5) 23 l2.PushBack(6) 24 l2.PushBack(7) 25 l2.PushBack(8) 26 27 l.PushBackQueue(l2) 28 29 l2.TrimFrontFunc(func(e int) bool { 30 return e%2 == 1 31 }) 32 // Iterate through list and print its contents. 33 l.Do(func(e int) { 34 fmt.Println(e) 35 }) 36 l2.Do(func(e int) { 37 fmt.Println(e) 38 }) 39 40 // Output: 41 // 1 42 // 2 43 // 3 44 // 4 45 // 5 46 // 6 47 // 7 48 // 8 49 // 6 50 // 7 51 // 8 52 }