Skip to content

Commit

Permalink
Merge pull request #2817 from aldacron/split-doc
Browse files Browse the repository at this point in the history
Ehance ddoc for std.array.split.
  • Loading branch information
AndrejMitrovic committed Jan 2, 2015
2 parents b7da866 + 42c5a2f commit 9509581
Showing 1 changed file with 30 additions and 11 deletions.
41 changes: 30 additions & 11 deletions std/array.d
Expand Up @@ -1309,29 +1309,48 @@ Alias for $(XREF algorithm, splitter).
deprecated("Please use std.algorithm.splitter instead.") alias splitter = std.algorithm.splitter;

/++
Eagerly splits $(D s) into an array, using $(D delim) as the delimiter.
Eagerly splits $(D range) into an array, using $(D sep) as the delimiter.
See_Also: $(XREF algorithm, splitter) for the lazy version of this operator.
The range must be a $(FULL_XREF std_range.html#isForwardRange, forward range).
The separator can be a value of the same type as the elements in $(D range) or
it can be another forward range.
Examples:
If $(D range) is a $(D string), $(D sep) can be a $(D char) or another
$(D string). The return type will be an array of strings. If $(D range) is
an $(D int) array, $(D sep) can be an $(D int) or another $(D int) array.
The return type will be an array of $(D int) arrays.
Params:
range = a forward range.
sep = a value of the same type as the elements of $(D range) or another
forward range.
Returns:
An array containing the divided parts of $(D range).
See_Also:
$(XREF algorithm, splitter) for the lazy version of this function.
+/
auto split(R, E)(R r, E delim)
if (isForwardRange!R && is(typeof(ElementType!R.init == E.init)))
auto split(Range, Separator)(Range range, Separator sep)
if (isForwardRange!Range && is(typeof(ElementType!Range.init == Separator.init)))
{
import std.algorithm : splitter;
return r.splitter(delim).array;
return range.splitter(sep).array;
}
///ditto
auto split(R1, R2)(R1 r, R2 delim)
if (isForwardRange!R1 && isForwardRange!R2 && is(typeof(ElementType!R1.init == ElementType!R2.init)))
auto split(Range, Separator)(Range range, Separator sep)
if (isForwardRange!Range && isForwardRange!Separator && is(typeof(ElementType!Range.init == ElementType!Separator.init)))
{
import std.algorithm : splitter;
return r.splitter(delim).array;
return range.splitter(sep).array;
}
///ditto
auto split(alias isTerminator, R)(R r)
if (isForwardRange!R && is(typeof(unaryFun!isTerminator(r.front))))
auto split(alias isTerminator, Range)(Range range)
if (isForwardRange!Range && is(typeof(unaryFun!isTerminator(range.front))))
{
import std.algorithm : splitter;
return r.splitter!isTerminator.array;
return range.splitter!isTerminator.array;
}

unittest
Expand Down

0 comments on commit 9509581

Please sign in to comment.