github.com/taylorchu/generic@v0.0.0-20171113184323-cd81575befa2/rewrite/_test/pkg/queue/queue.go (about)

     1  package queue
     2  
     3  type Type string
     4  
     5  // TypeQueue represents a queue of Type types.
     6  type TypeQueue struct {
     7  	items []Type
     8  }
     9  
    10  // New makes a new empty Type queue.
    11  func New() *TypeQueue {
    12  	return &TypeQueue{items: make([]Type, 0)}
    13  }
    14  
    15  // Enq adds an item to the queue.
    16  func (q *TypeQueue) Enq(obj Type) *TypeQueue {
    17  	q.items = append(q.items, obj)
    18  	return q
    19  }
    20  
    21  // Deq removes and returns the next item in the queue.
    22  func (q *TypeQueue) Deq() Type {
    23  	obj := q.items[0]
    24  	q.items = q.items[1:]
    25  	return obj
    26  }
    27  
    28  // Len gets the current number of Type items in the queue.
    29  func (q *TypeQueue) Len() int {
    30  	return len(q.items)
    31  }