{"id":"6b08bd3980884893657cc996","slug":"iterator","title":"Iterator: walking a collection without looking inside","summary":"The Iterator pattern through orders from a delivery app fetched page by page: the loop in the report knows nothing about pagination, and pages load lazily, only when needed. Generators, yield and iter.Seq in five languages.","servedLang":"en","availableLangs":["pl","en"],"topics":["iterator"],"techs":["dotnet","typescript","java","go","python"],"tags":["gof","behavioral","iterator","generators","lazy-evaluation","pagination"],"level":"beginner","kind":"article","access":"members","status":"published","cover":null,"author":{"id":"6b08bd2e80884893657cc8cf","name":"Redakcja Art of Devs","avatar":null,"handle":"redakcja","community":false},"readingMinutes":11,"stats":{"views":2,"likes":0,"bookmarks":0,"comments":0},"publishedAt":"2026-11-26T23:14:01.513Z","updatedAt":"2026-11-27T13:06:54.504Z","requestedLang":"en","theme":{"hero":"classic","heroMedia":null,"accent":"violet","background":"hex","weaveResources":true,"toc":"right"},"seoDescription":"The Iterator design pattern in C#, TypeScript, Java, Go and Python: external and internal iterators, generators and yield, lazy API pagination, async iteration.","wordCount":2108,"doc":{"type":"doc","content":[{"type":"paragraph","content":[{"type":"text","text":"Halina's pierogi place also takes orders through a delivery app whose API returns them in pages of 50. The daily report, the VAT export and the courier statistics simply want to \"walk through all the orders\". "},{"type":"text","text":"Iterator","marks":[{"type":"bold"}]},{"type":"text","text":" gives them a single "},{"type":"text","text":"for","marks":[{"type":"code"}]},{"type":"text","text":" loop and hides the details – pages, cursors, further HTTP requests – inside."}]},{"type":"callout","attrs":{"variant":"tip","title":"In short"},"content":[{"type":"bulletList","content":[{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"An iterator is an object that "},{"type":"text","text":"returns the next elements","marks":[{"type":"bold"}]},{"type":"text","text":" of a collection and remembers where it stopped."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"The client does not know the collection's internal structure – an array, a tree, a paginated API."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"Today the pattern is "},{"type":"text","text":"built into languages","marks":[{"type":"bold"}]},{"type":"text","text":": "},{"type":"text","text":"foreach","marks":[{"type":"code"}]},{"type":"text","text":", "},{"type":"text","text":"for...of","marks":[{"type":"code"}]},{"type":"text","text":", "},{"type":"text","text":"for range","marks":[{"type":"code"}]},{"type":"text","text":", "},{"type":"text","text":"for in","marks":[{"type":"code"}]},{"type":"text","text":" and generators with "},{"type":"text","text":"yield","marks":[{"type":"code"}]},{"type":"text","text":"."}]}]}]}]},{"type":"stats","attrs":{"items":[{"value":"3","label":"pages in the example","hint":"only 2 will be fetched"},{"value":"1","label":"loop in the client code","hint":"with no knowledge of pagination"},{"value":"5","label":"languages with a built-in protocol","hint":"IEnumerable, Iterable, iter.Seq, __iter__, Symbol.iterator"}]}},{"type":"heading","attrs":{"level":2,"id":"the-problem-a-loop-that-knows-too-much"},"content":[{"type":"text","text":"The problem: a loop that knows too much"}]},{"type":"paragraph","content":[{"type":"text","text":"The first version of the report handled pagination itself:"}]},{"type":"codeBlock","attrs":{"language":"typescript","filename":"daily-report-before.ts"},"content":[{"type":"text","text":"async function dailyRevenue(): Promise<number> {\n  let page = 1;\n  let revenue = 0;\n  while (true) {\n    const res = await http.get(`/orders?page=${page}&size=50`);\n    for (const order of res.data.items) revenue += order.total;\n    if (!res.data.hasMore) break; // API v2 switches to cursors: res.headers['x-next-cursor']\n    page++;\n  }\n  return revenue;\n}\n// ...and the same loop is copied into the VAT export, the courier stats and the loyalty sync"}]},{"type":"paragraph","content":[{"type":"text","text":"The business logic (summing up revenue) is mixed with the fetching mechanics (page numbers, size, the "},{"type":"text","text":"hasMore","marks":[{"type":"code"}]},{"type":"text","text":" flag). The same loop ended up in three other places, so when the API provider switches to cursors, four copies will need fixing. On top of that, the report always fetches everything, even if it only needs the first two large orders."}]},{"type":"heading","attrs":{"level":2,"id":"the-solution-separate-traversal-from-the-collection"},"content":[{"type":"text","text":"The solution: separate traversal from the collection"}]},{"type":"paragraph","content":[{"type":"text","text":"The iterator takes over responsibility for "},{"type":"text","text":"how to traverse","marks":[{"type":"bold"}]},{"type":"text","text":". The collection (here: \"all orders from the API\") exposes a method that returns an iterator, and the iterator offers two operations: \"is there a next one?\" and \"give me the next one\". When the current page buffer runs out, the iterator fetches the next page itself. The client sees a flat stream of orders."}]},{"type":"diagram","attrs":{"kind":"mermaid","code":"sequenceDiagram\n  participant R as Report (client)\n  participant I as OrderIterator\n  participant A as Provider API\n  R->>I: next()\n  I->>A: GET /orders?page=1\n  A-->>I: [1, 2], hasMore\n  I-->>R: order 1\n  R->>I: next()\n  I-->>R: order 2 (from the buffer)\n  R->>I: next()\n  I->>A: GET /orders?page=2\n  A-->>I: [3, 4], hasMore\n  I-->>R: order 3\n  Note over R,I: the client ends the loop – page 3 is never fetched","caption":"Lazy page fetching by the iterator"}},{"type":"diagram","attrs":{"kind":"mermaid","code":"classDiagram\n  direction LR\n  class Iterable~T~ {\n    <<interface>>\n    +iterator() Iterator~T~\n  }\n  class Iterator~T~ {\n    <<interface>>\n    +hasNext() bool\n    +next() T\n  }\n  class AllOrders {\n    +iterator() OrderIterator\n  }\n  class OrderIterator {\n    -current page buffer\n    -nextPage\n    +hasNext() bool\n    +next() Order\n  }\n  Iterable <|.. AllOrders\n  Iterator <|.. OrderIterator\n  AllOrders ..> OrderIterator : creates","caption":"Participants of the Iterator pattern"}},{"type":"table","content":[{"type":"tableRow","content":[{"type":"tableHeader","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Role"}]}]},{"type":"tableHeader","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"In the example"}]}]},{"type":"tableHeader","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Responsibility"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Aggregate ("},{"type":"text","text":"Iterable","marks":[{"type":"italic"}]},{"type":"text","text":")"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"AllOrders","marks":[{"type":"code"}]}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"creates an iterator; does not expose its structure"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Iterator"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Iterator<Order>","marks":[{"type":"code"}]}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"the interface: next element, end of sequence"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Concrete iterator"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"OrderIterator","marks":[{"type":"code"}]},{"type":"text","text":", a generator"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"remembers the position, fetches further pages"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Client"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"the daily report"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"walks the elements with a single loop"}]}]}]}]},{"type":"heading","attrs":{"level":2,"id":"implementation-in-five-languages"},"content":[{"type":"text","text":"Implementation in five languages"}]},{"type":"paragraph","content":[{"type":"text","text":"Java shows a classic external iterator with "},{"type":"text","text":"hasNext()","marks":[{"type":"code"}]},{"type":"text","text":"/"},{"type":"text","text":"next()","marks":[{"type":"code"}]},{"type":"text","text":". In C#, TypeScript and Python the same object is generated for us by the compiler or interpreter – a function with "},{"type":"text","text":"yield","marks":[{"type":"code"}]},{"type":"text","text":" is enough. Since version 1.23 Go has the "},{"type":"text","text":"iter.Seq","marks":[{"type":"code"}]},{"type":"text","text":" type and "},{"type":"text","text":"range","marks":[{"type":"code"}]},{"type":"text","text":" over functions. In every variant breaking out of the loop means the third page "},{"type":"text","text":"is never fetched","marks":[{"type":"bold"}]},{"type":"text","text":"."}]},{"type":"codeGroup","attrs":{"title":"Iterator – orders from a paginated API"},"content":[{"type":"codeBlock","attrs":{"language":"csharp","filename":"AllOrders.cs"},"content":[{"type":"text","text":"var api = new FakeOrdersApi();\n\n// Lazy: pages are fetched only while the pipeline needs more orders.\nforeach (var order in AllOrders(api).Where(o => o.Total >= 100).Take(2))\n    Console.WriteLine($\"#{order.Id}: {order.Total} PLN\");\n// GET /orders?page=1, #2: 120 PLN, GET /orders?page=2, #4: 210 PLN – page 3 is never fetched\n\nstatic IEnumerable<Order> AllOrders(IOrdersApi api)\n{\n    for (var number = 1; ; number++)\n    {\n        var page = api.GetPage(number);\n        foreach (var order in page.Items)\n            yield return order; // the compiler turns this method into an iterator object\n        if (!page.HasMore) yield break;\n    }\n}\n\npublic sealed record Order(int Id, decimal Total);\npublic sealed record Page(IReadOnlyList<Order> Items, bool HasMore);\n\npublic interface IOrdersApi\n{\n    Page GetPage(int number);\n}\n\npublic sealed class FakeOrdersApi : IOrdersApi\n{\n    private readonly Order[][] _pages =\n    [\n        [new(1, 45m), new(2, 120m)],\n        [new(3, 80m), new(4, 210m)],\n        [new(5, 150m)],\n    ];\n\n    public Page GetPage(int number)\n    {\n        Console.WriteLine($\"GET /orders?page={number}\");\n        return new Page(_pages[number - 1], number < _pages.Length);\n    }\n}"}]},{"type":"codeBlock","attrs":{"language":"typescript","filename":"all-orders.ts"},"content":[{"type":"text","text":"type Order = { id: number; total: number };\ntype Page = { items: Order[]; hasMore: boolean };\n\nconst pages: Order[][] = [\n  [{ id: 1, total: 45 }, { id: 2, total: 120 }],\n  [{ id: 3, total: 80 }, { id: 4, total: 210 }],\n  [{ id: 5, total: 150 }],\n];\n\nfunction getPage(n: number): Page {\n  console.log(`GET /orders?page=${n}`);\n  return { items: pages[n - 1], hasMore: n < pages.length };\n}\n\n// The collection hides paging; any for...of loop or spread can walk it.\nclass AllOrders implements Iterable<Order> {\n  constructor(private readonly fetch: (n: number) => Page) {}\n\n  *[Symbol.iterator](): Iterator<Order> {\n    for (let n = 1; ; n++) {\n      const page = this.fetch(n);\n      yield* page.items;\n      if (!page.hasMore) return;\n    }\n  }\n}\n\nlet found = 0;\nfor (const order of new AllOrders(getPage)) {\n  if (order.total < 100) continue;\n  console.log(`#${order.id}: ${order.total} PLN`);\n  if (++found === 2) break; // break calls return() on the generator – page 3 is never fetched\n}\n\n// Under the hood it is the classic protocol: next() returns { value, done }.\nconst it = new AllOrders(getPage)[Symbol.iterator]();\nconsole.log(it.next()); // { value: { id: 1, total: 45 }, done: false }"}]},{"type":"codeBlock","attrs":{"language":"java","filename":"AllOrders.java"},"content":[{"type":"text","text":"import java.util.Iterator;\nimport java.util.List;\nimport java.util.NoSuchElementException;\nimport java.util.function.IntFunction;\n\nrecord Order(int id, int total) {}\nrecord Page(List<Order> items, boolean hasMore) {}\n\n// A classic external iterator: the client pulls elements with hasNext()/next().\nclass OrderIterator implements Iterator<Order> {\n    private final IntFunction<Page> api;\n    private Iterator<Order> current = List.<Order>of().iterator();\n    private int nextPage = 1;\n    private boolean more = true;\n\n    OrderIterator(IntFunction<Page> api) { this.api = api; }\n\n    @Override public boolean hasNext() {\n        while (!current.hasNext() && more) { // fetch lazily, skipping empty pages\n            Page page = api.apply(nextPage++);\n            current = page.items().iterator();\n            more = page.hasMore();\n        }\n        return current.hasNext();\n    }\n\n    @Override public Order next() {\n        if (!hasNext()) throw new NoSuchElementException();\n        return current.next();\n    }\n}\n\npublic class AllOrders implements Iterable<Order> {\n    private static final List<List<Order>> PAGES = List.of(\n        List.of(new Order(1, 45), new Order(2, 120)),\n        List.of(new Order(3, 80), new Order(4, 210)),\n        List.of(new Order(5, 150)));\n\n    static Page getPage(int n) {\n        System.out.println(\"GET /orders?page=\" + n);\n        return new Page(PAGES.get(n - 1), n < PAGES.size());\n    }\n\n    @Override public Iterator<Order> iterator() { return new OrderIterator(AllOrders::getPage); }\n\n    public static void main(String[] args) {\n        int found = 0;\n        for (Order o : new AllOrders()) { // for-each works with any Iterable\n            if (o.total() < 100) continue;\n            System.out.println(\"#\" + o.id() + \": \" + o.total() + \" PLN\");\n            if (++found == 2) break; // page 3 is never fetched\n        }\n    }\n}"}]},{"type":"codeBlock","attrs":{"language":"go","filename":"orders.go"},"content":[{"type":"text","text":"package main\n\nimport (\n\t\"fmt\"\n\t\"iter\"\n)\n\ntype Order struct{ ID, Total int }\n\ntype Page struct {\n\tItems   []Order\n\tHasMore bool\n}\n\nvar pages = [][]Order{{{1, 45}, {2, 120}}, {{3, 80}, {4, 210}}, {{5, 150}}}\n\nfunc getPage(n int) Page {\n\tfmt.Printf(\"GET /orders?page=%d\\n\", n)\n\treturn Page{pages[n-1], n < len(pages)}\n}\n\n// AllOrders returns a lazy sequence (Go 1.23+); it stops as soon as yield returns false.\nfunc AllOrders(fetch func(int) Page) iter.Seq[Order] {\n\treturn func(yield func(Order) bool) {\n\t\tfor n := 1; ; n++ {\n\t\t\tpage := fetch(n)\n\t\t\tfor _, o := range page.Items {\n\t\t\t\tif !yield(o) {\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t}\n\t\t\tif !page.HasMore {\n\t\t\t\treturn\n\t\t\t}\n\t\t}\n\t}\n}\n\nfunc main() {\n\tfound := 0\n\tfor o := range AllOrders(getPage) {\n\t\tif o.Total < 100 {\n\t\t\tcontinue\n\t\t}\n\t\tfmt.Printf(\"#%d: %d PLN\\n\", o.ID, o.Total)\n\t\tfound++\n\t\tif found == 2 {\n\t\t\tbreak // yield returns false – page 3 is never fetched\n\t\t}\n\t}\n}"}]},{"type":"codeBlock","attrs":{"language":"python","filename":"all_orders.py"},"content":[{"type":"text","text":"from dataclasses import dataclass\nfrom itertools import islice\nfrom typing import Callable, Iterator\n\n\n@dataclass(frozen=True)\nclass Order:\n    id: int\n    total: int\n\n\n@dataclass(frozen=True)\nclass Page:\n    items: list[Order]\n    has_more: bool\n\n\nPAGES = [[Order(1, 45), Order(2, 120)], [Order(3, 80), Order(4, 210)], [Order(5, 150)]]\n\n\ndef get_page(n: int) -> Page:\n    print(f\"GET /orders?page={n}\")\n    return Page(PAGES[n - 1], n < len(PAGES))\n\n\ndef all_orders(fetch: Callable[[int], Page]) -> Iterator[Order]:\n    \"\"\"A generator is an iterator: it hides paging and fetches pages lazily.\"\"\"\n    n = 1\n    while True:\n        page = fetch(n)\n        yield from page.items\n        if not page.has_more:\n            return\n        n += 1\n\n\nbig_orders = (o for o in all_orders(get_page) if o.total >= 100)\nfor order in islice(big_orders, 2):  # take two – page 3 is never fetched\n    print(f\"#{order.id}: {order.total} PLN\")"}]}]}]},"toc":[{"id":"the-problem-a-loop-that-knows-too-much","text":"The problem: a loop that knows too much","level":2,"locked":false},{"id":"the-solution-separate-traversal-from-the-collection","text":"The solution: separate traversal from the collection","level":2,"locked":false},{"id":"implementation-in-five-languages","text":"Implementation in five languages","level":2,"locked":false},{"id":"external-and-internal-iterators","text":"External and internal iterators","level":2,"locked":true},{"id":"laziness-pipelines-and-pitfalls","text":"Laziness, pipelines and pitfalls","level":2,"locked":true},{"id":"when-to-use-it-and-when-not-to","text":"When to use it and when not to","level":2,"locked":true},{"id":"related-patterns","text":"Related patterns","level":2,"locked":true},{"id":"in-practice","text":"In practice","level":2,"locked":true},{"id":"test-yourself","text":"Test yourself","level":2,"locked":true}],"locked":true,"paywall":null,"previewRatio":0.3,"totalBlocks":35,"visibleBlocks":15,"resources":[{"id":"6b0857bf3c96f2d34d0b42c8","type":"article","provider":"web","url":"https://refactoring.guru/pl/design-patterns/iterator","embedUrl":null,"title":"Iterator / Iterator","description":"Iterator to behawioralny wzorzec projektowy, pozwalający sekwencyjnie przechodzić od elementu do elementu jakiegoś zbioru bez konieczności eksponowania jego formy (lista, stos, drzewo, itp.).","author":"Refactoring.Guru","thumbnailUrl":"https://refactoring.guru/pl/images/refactoring/social/facebook-share-preview.png?id=dbf9e98269595be86eb668f365be6868","durationSec":null,"lang":"pl","topics":["iterator"],"techs":["general"],"tags":["design-patterns"],"price":"free","featured":false,"featuredOrder":0,"packageName":null,"source":"manual","publishedAt":null,"popularity":60,"verifiedAt":"2026-11-26T11:26:12.000Z","curated":false,"addedBy":"6b0857a15a2625e44ecaabe6","createdAt":"2026-11-26T16:01:02.417Z","updatedAt":"2026-11-26T16:01:02.417Z"},{"id":"6b0857be3c96f2d34d0b4203","type":"article","provider":"web","url":"https://martinfowler.com/articles/collection-pipeline","embedUrl":null,"title":"Collection Pipeline","description":"Collection pipelines are a programming pattern where you organize computation as a sequence of operations which compose by taking a collection as output of one and feeding it into the next.","author":"Martin Fowler","thumbnailUrl":"https://martinfowler.com/articles/collection-pipeline/collection-pipeline/sketch.png","durationSec":null,"lang":"en","topics":[],"techs":["general"],"tags":["martin-fowler"],"price":"free","featured":false,"featuredOrder":0,"packageName":null,"source":"manual","publishedAt":null,"popularity":75,"verifiedAt":"2026-11-26T11:07:27.000Z","curated":false,"addedBy":"6b0857a15a2625e44ecaabe6","createdAt":"2026-11-26T16:00:59.965Z","updatedAt":"2026-11-26T16:00:59.965Z"},{"id":"6b0857bc3c96f2d34d0b4047","type":"podcast","provider":"apple-podcasts","url":"https://podcasts.apple.com/us/podcast/design-patterns-iterators-observers-and-chains-oh-my/id769189585?i=1000378375263","embedUrl":"https://embed.podcasts.apple.com/us/podcast/id769189585?i=1000378375263","title":"Design Patterns – Iterators, Observers, and Chains, Oh My","description":"We’re back to the gang of four, continuing with another segment of design patterns. This time we’re talking about some of our favorite Behavioral Design Patterns: Observer, Chain of Responsibilities, Iterator patterns. Also, why the visitor pattern is weird and what it’s like to be raked over hot…","author":"Coding Blocks","thumbnailUrl":"https://is1-ssl.mzstatic.com/image/thumb/Podcasts113/v4/f0/b6/68/f0b6682f-e8bc-181c-95a9-0756ddf63d6e/mza_3128980961332034780.jpg/600x600bb.jpg","durationSec":3828,"lang":"en","topics":["iterator","visitor"],"techs":["general"],"tags":["podcast","design-patterns"],"price":"free","featured":false,"featuredOrder":0,"packageName":null,"source":"itunes","publishedAt":"2014-11-09T01:53:47.000Z","popularity":44,"verifiedAt":"2026-11-26T10:57:23.000Z","curated":false,"addedBy":"6b0857a15a2625e44ecaabe6","createdAt":"2026-11-26T16:00:59.965Z","updatedAt":"2026-11-26T16:00:59.965Z"},{"id":"6b0857c33c96f2d34d0b4666","type":"book","provider":"openlibrary","url":"https://openlibrary.org/works/OL16942701W","embedUrl":null,"title":"Head First design patterns","description":"","author":"Eric Freeman, Elisabeth Freeman, Kathy Sierra, Bert Bates","thumbnailUrl":"https://covers.openlibrary.org/b/id/388950-L.jpg","durationSec":null,"lang":"en","topics":["factory-method","abstract-factory","builder","prototype","singleton","adapter","bridge","composite","decorator","facade","flyweight","proxy","chain-of-responsibility","command","iterator","mediator","memento","observer","state","strategy","template-method","visitor"],"techs":["java"],"tags":["book","design-patterns"],"price":"paid","featured":false,"featuredOrder":0,"packageName":null,"source":"openlibrary","publishedAt":"2004-01-01T00:00:00.000Z","popularity":62,"verifiedAt":"2026-11-26T11:00:08.000Z","curated":false,"addedBy":"6b0857a15a2625e44ecaabe6","createdAt":"2026-11-26T16:01:04.995Z","updatedAt":"2026-11-26T16:01:04.995Z"}],"challenges":[{"id":"6b093dc191bd8fbaf2a0c8d4","slug":"paged-results-iterator","title":"Lazy iterator over a paged API","summary":"Orders from an API that returns pages with a cursor, exposed as one collection – lazy page fetching, skipping empty pages, protection against a looping cursor and the native iteration protocol of every language.","servedLang":"en","availableLangs":["pl","en"],"kind":"code","category":"pattern","status":"published","difficulty":"medium","topics":["iterator"],"techs":["typescript","javascript","python","dotnet","java","go"],"tags":["iterator","pagination","lazy-evaluation","generators","behavioral"],"languages":["typescript","javascript","python","csharp","java","go"],"questionCount":null,"xp":20,"stats":{"attempts":0,"solves":0,"solutions":0,"comments":0},"solveRate":null,"publishedAt":"2026-11-27T08:22:25.658Z"}],"attachments":[],"hasCode":true,"repoUrl":null,"series":[{"slug":"gof-behavioral","title":"GoF behavioral patterns","items":[{"slug":"strategy","title":"Strategy: interchangeable algorithms instead of an if-else ladder","current":false},{"slug":"observer","title":"Observer: notify everyone without knowing anyone","current":false},{"slug":"command","title":"Command: a request wrapped in an object","current":false},{"slug":"state","title":"State: an object that changes behaviour with its life stage","current":false},{"slug":"template-method","title":"Template Method: a fixed recipe, interchangeable ingredients","current":false},{"slug":"iterator","title":"Iterator: walking a collection without looking inside","current":true},{"slug":"chain-of-responsibility","title":"Chain of Responsibility: pass it on until someone takes care of it","current":false},{"slug":"mediator","title":"Mediator: components talk through a coordinator","current":false},{"slug":"memento","title":"Memento: a state snapshot without breaking encapsulation","current":false},{"slug":"visitor","title":"Visitor: new operations without changing classes","current":false}]}],"prev":{"slug":"template-method","title":"Template Method: a fixed recipe, interchangeable ingredients"},"next":{"slug":"chain-of-responsibility","title":"Chain of Responsibility: pass it on until someone takes care of it"},"featured":false,"authorCard":{"id":"6b08bd2e80884893657cc8cf","name":"Redakcja Art of Devs","avatar":null,"handle":"redakcja","headline":"Wzorce projektowe · Architektura · AI i LLM","community":false,"reputation":{"points":3900,"level":{"key":"mentor","label":"Mentor"}},"articles":68,"skills":[{"key":"typescript","title":"TypeScript","level":5,"levelLabel":"Authority","articles":63},{"key":"dotnet","title":".NET","level":5,"levelLabel":"Authority","articles":53},{"key":"python","title":"Python","level":5,"levelLabel":"Authority","articles":52},{"key":"java","title":"Java","level":5,"levelLabel":"Authority","articles":38}]}}