The Iterator of the Ley Lines
Sequentially accessing nodes in a magical ley line network.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Iterator
ARCANUM SCHOOL: Divination // Ley Lines
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// CODEX INCANTATION //
module Iterator
type node = { mana: nat }
type ley_line = list node
let has_next (l: ley_line) : bool =
match l with | [] -> false | _ -> true
let next (l: ley_line{has_next l}) : node * ley_line =
match l with
| h :: t -> (h, t)
A verified iterator that guarantees via refinement types that next can only be called if there are still magical nodes remaining.
Runic Tags:
#iterator
#traversal
#sequences