⚙️ JSONNET RUNE DIFFICULTY: Apprentice Behavioral

The Iterator of Jsonnet

Sequentially accessing elements of a collection.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Iterator
ARCANUM SCHOOL: Divination // Leyline Tracing
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// JSONNET PATTERN //
local ProcessList(list, fn) =
  [fn(item) for item in list];

local Collection = [1, 2, 3, 4];

{
  doubled: ProcessList(Collection, function(x) x * 2),
  strings: ProcessList(Collection, function(x) "Item " + x)
}

List comprehensions provide a powerful form of iteration natively in Jsonnet, allowing the transformation of arrays effortlessly through functional mapping.

Runic Tags: #behavioral #iterator #jsonnet