✨ ARCANUM RUNE DIFFICULTY: Apprentice Behavioral

Iterator in Elm

Traversing data structures using Elm's native List operations.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Iterator
ARCANUM SCHOOL: Divination // Sequential Scrying
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// CODEX INCANTATION //
module Iterator exposing (processLogStream)

-- In Elm, iteration is natively handled by List.map, List.filter, and List.foldl

type alias LogEntry =
    { timestamp : Int, message : String, isError : Bool }

processLogStream : List LogEntry -> List String
processLogStream logs =
    logs
        |> List.filter .isError
        |> List.map (\log -> "ERR [" ++ String.fromInt log.timestamp ++ "]: " ++ log.message)
        
-- Or for stateful accumulation (reducing)
countErrors : List LogEntry -> Int
countErrors logs =
    List.foldl (\log acc -> if log.isError then acc + 1 else acc) 0 logs

The Iterator: The Stream of Consciousness

The object-oriented Iterator—with its mutable hasNext() and next() calls—is a relic of a bygone era. In Elm, iteration is achieved purely and safely through higher-order functions like List.map, List.filter, and List.foldl. The alchemist strings these functions together via the pipeline operator, transforming a raw data stream into a refined sequence of truths without ever mutating a single loop counter.

Runic Tags: #elm #behavioral #iterator #list-processing #higher-order-functions