✨ ARCANUM RUNE DIFFICULTY: Archmage Behavioral

The Line Walker (Iterator)

Sequentially accessing lines in an aggregated buffer without exposing its internal representation.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Iterator
ARCANUM SCHOOL: Transmutation // Streamweaving
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// CODEX INCANTATION //
# Iterator: Process a multi-line buffer line by line
# Let's say we read the entire file into hold space
H
$ {
  g
  :loop
  # Extract first line of the buffer
  s/^\([^\n]*\)\n\(.*\)/\1/
  p
  # Restore the rest of the buffer
  g
  s/^\([^\n]*\)\n\(.*\)/\2/
  h
  # Repeat until buffer is empty
  /[^\n]/ b loop
}
d
Runic Tags: #sed #behavioral #iterator