The Iterator: Walking the Timeline
Traversing complex temporal collections without exposing underlying representations.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Iterator
ARCANUM SCHOOL: Divination // Temporal Stepping
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// R PATTERN //
library(R6)
# Iterator Interface
Iterator <- R6Class("Iterator",
public = list(
has_next = function() stop("Not implemented"),
next_item = function() stop("Not implemented")
)
)
# Concrete Iterator
TimelineIterator <- R6Class("TimelineIterator", inherit = Iterator,
private = list(
collection = NULL,
position = 0
),
public = list(
initialize = function(collection) {
private$collection <- collection
private$position <- 1
},
has_next = function() {
return(private$position <= length(private$collection))
},
next_item = function() {
if (self$has_next()) {
item <- private$collection[private$position]
private$position <- private$position + 1
return(item)
}
return(NULL)
}
)
)
Walk linearly through the branches of time. The Iterator shields the Data Haruspex from the underlying implementation of the multiverse data structure.
Runic Tags:
#R6
#Divination
#Behavioral
#Iterator