daily pastebin goal
18%
SHARE
TWEET

[Go] Queue template for genny

cwchen Nov 21st, 2017 143 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package example
  2.  
  3. import "github.com/cheekybits/genny/generic"
  4.  
  5. type Generic generic.Type
  6.  
  7. // GenericQueue represents a queue of Generic types.
  8. type GenericQueue struct {
  9.     items []Generic
  10. }
  11.  
  12. // NewGenericQueue makes a new empty Generic queue.
  13. func NewGenericQueue() *GenericQueue {
  14.     return &GenericQueue{items: make([]Generic, 0)}
  15. }
  16.  
  17. // Enq adds an item to the queue.
  18. func (q *GenericQueue) Enq(obj Generic) *GenericQueue {
  19.     q.items = append(q.items, obj)
  20.     return q
  21. }
  22.  
  23. // Deq removes and returns the next item in the queue.
  24. func (q *GenericQueue) Deq() Generic {
  25.     obj := q.items[0]
  26.     q.items = q.items[1:]
  27.     return obj
  28. }
  29.  
  30. // Len gets the current number of Generic items in the queue.
  31. func (q *GenericQueue) Len() int {
  32.     return len(q.items)
  33. }
RAW Paste Data
Top