Process data lazily with D ranges and UFCS

8 steps · about 2 h 10 min · Intermediate

  1. Learn the input range interface (tutorial, DLang Tour, 12 min)

    empty, front and popFront are all a type needs to be a range.

  2. Chain calls left to right with UFCS (tutorial, DLang Tour, 10 min)

    Lets free functions read like methods in a pipeline.

  3. Combine map, filter and take in one pipeline (tutorial, DLang Tour, 15 min)

    Runnable examples of lazy algorithms from Phobos.

  4. Write your own range type (tutorial, Programming in D (Ali Cehreli), 35 min)

    Builds ranges step by step and explains forward, bidirectional and random-access kinds.

  5. Check range kinds with isInputRange and friends (reference, dlang.org, 10 min)

    The traits you use to constrain templates that accept ranges.

  6. Stream a file with File.byLine (reference, dlang.org, 10 min)

    Reads lines lazily so large files never sit in memory.

  7. Collect a range into an array only when needed (reference, dlang.org, 8 min)

    array and appender end a lazy pipeline with real storage.

  8. Read a full component-programming walk-through (article, D Wiki, 30 min)

    Shows a calendar printer built entirely from composed ranges.