joiner

Lazily joins a range of ranges with a separator. The separator itself is a range. If a separator is not provided, then the ranges are joined directly without anything in between them (often called flatten in other languages).

  1. auto joiner(RoR r, Separator sep)
    joiner
    (
    RoR
    Separator
    )
    (
    RoR r
    ,
    Separator sep
    )
    if (
    isInputRange!RoR &&
    isInputRange!(ElementType!RoR)
    &&
    isForwardRange!Separator
    &&
    is(ElementType!Separator : ElementType!(ElementType!RoR))
    )
  2. auto joiner(RoR r)

Parameters

r
Type: RoR

An input range of input ranges to be joined.

sep
Type: Separator

A forward range of element(s) to serve as separators in the joined range.

Return Value

Type: auto

A range of elements in the joined range. This will be a forward range if both outer and inner ranges of RoR are forward ranges; otherwise it will be only an input range.

Examples

1 import std.algorithm.comparison : equal;
2 import std.conv : text;
3 
4 assert(["abc", "def"].joiner.equal("abcdef"));
5 assert(["Mary", "has", "a", "little", "lamb"]
6     .joiner("...")
7     .equal("Mary...has...a...little...lamb"));
8 assert(["", "abc"].joiner("xyz").equal("xyzabc"));
9 assert([""].joiner("xyz").equal(""));
10 assert(["", ""].joiner("xyz").equal("xyz"));

See Also

std.range.chain, which chains a sequence of ranges with compatible elements into a single range.

Meta