liveBook · Manning

Queue

As explained in Go in Practice, Second Edition

A queue is a data structure that removes elements in the order they were inserted.

A queue removes elements in insertion order: first in, first out (FIFO). A practical Go implementation stores values in a slice, inserts with append, and removes the first element by reslicing. section 13.3

A simple queue exposes two operations:

  • Type-specific queues avoid type assertions and can reduce duplicated collection code. section 13.3

Generated typed queue

Declare //go:generate ./queue MyInt, run go generate, and use NewMyIntQueue with Insert(1), Insert(2), and Insert(3). Remove returns 1.

How Go in Practice, Second Edition covers it

How deep it goes
Explains FIFO operations and slice mechanics, then stops short of advanced queue behavior or performance analysis.
Examples
Demonstrates generated MyInt queues, go:generate directives, command execution, and FIFO output.
What it assumes
Assumes basic Go types, methods, slices, files, and commands while demonstrating generation from a working queue.
What you can do after
Build it from scratch as a slice-backed queue or generate typed variants with go:generate and text/template.
How it connects
Connects queues with code generation, Go templates, slices, generics, and type assertions.

Also explained in

Compare how 24 books explain queue →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Go in Practice, Second Edition. The section links point to the parts of the book it draws on.