View source code
Display the source code in std/algorithm/iteration.d from which this page was generated on
github.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.
Requires a signed-in GitHub account. This works well for small changes.
If you'd like to make larger changes you may want to consider using
local clone.
Page wiki
View or edit the community-maintained wiki page associated with this page.
Function std.algorithm.iteration.joiner
Lazily joins a range of ranges with a separator. The separator itself is a range. If you do not provide a separator, then the ranges are joined directly without anything in between them.
Prototypes
auto joiner(RoR, Separator)( RoR r, Separator sep ) if (isInputRange!RoR && isInputRange!(ElementType!RoR) && isForwardRange!Separator && is(ElementType!Separator : ElementType!(ElementType!RoR))); auto joiner(RoR)( RoR r ) if (isInputRange!RoR && isInputRange!(ElementType!RoR));
Parameters
Name | Description |
---|---|
r | An input range of input ranges to be joined. |
sep | A forward range of element(s) to serve as separators in the joined range. |
Returns
An input 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.
See also
std.range.chain, which chains a sequence of ranges with compatible elements into a single range.
Example
import std.algorithm.comparison : equal; import std.conv : text; debug(std_algorithm) scope(success) writeln("unittest @", __FILE__, ":", __LINE__, " done."); static assert(isInputRange!(typeof(joiner([""], "")))); static assert(isForwardRange!(typeof(joiner([""], "")))); assert(equal(joiner([""], "xyz"), ""), text(joiner([""], "xyz"))); assert(equal(joiner(["", ""], "xyz"), "xyz"), text(joiner(["", ""], "xyz"))); assert(equal(joiner(["", "abc"], "xyz"), "xyzabc")); assert(equal(joiner(["abc", ""], "xyz"), "abcxyz")); assert(equal(joiner(["abc", "def"], "xyz"), "abcxyzdef")); assert(equal(joiner(["Mary", "has", "a", "little", "lamb"], "..."), "Mary...has...a...little...lamb")); assert(equal(joiner(["abc", "def"]), "abcdef"));