⚙️ ISABELLE RUNE DIFFICULTY: Adept Behavioral

The Iterator

Provide a way to access the elements of an aggregate mathematical object sequentially without exposing its underlying representation.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Iterator
ARCANUM SCHOOL: Abjuration // Enumeration
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// ISABELLE PATTERN //
theory Iterator
  imports Main
begin

record 'a iterator =
  has_next :: "bool"
  next_val :: "'a option"
  step :: "'a iterator"

fun list_iterator :: "'a list \<Rightarrow> 'a iterator" where
  "list_iterator [] = \<lparr> has_next = False, next_val = None, step = undefined \<rparr>"
| "list_iterator (x#xs) = \<lparr> has_next = True, next_val = Some x, step = list_iterator xs \<rparr>"

end
Runic Tags: #isabelle #hol #abjuration #design-patterns