🧮 MATLAB THAUMATURGY DIFFICULTY: Apprentice Behavioral

The Iterator of Dimensional Traversal

Sequentially access elements of a multi-dimensional spell matrix without exposing its underlying structure.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Iterator
ARCANUM SCHOOL: Divination // Traversal
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// MATLAB PATTERN //
classdef MatrixIterator < handle
    properties
        Matrix
        CurrentIndex
    end
    methods
        function obj = MatrixIterator(mat)
            obj.Matrix = mat;
            obj.CurrentIndex = 1;
        end
        function val = next(obj)
            val = obj.Matrix(obj.CurrentIndex);
            obj.CurrentIndex = obj.CurrentIndex + 1;
        end
        function b = hasNext(obj)
            b = obj.CurrentIndex <= numel(obj.Matrix);
        end
    end
end

Iterator

Walk the path of the elements in linear time, ignorant of the hyperspatial folding that contains them.

Runic Tags: #iterator #traversal #matrices