[Issue 13409] New: std.range.padLeft/Right
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Sun Aug 31 13:15:44 PDT 2014
https://issues.dlang.org/show_bug.cgi?id=13409
Issue ID: 13409
Summary: std.range.padLeft/Right
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: enhancement
Priority: P1
Component: Phobos
Assignee: nobody at puremagic.com
Reporter: peter.alexander.au at gmail.com
Would be useful to have two new higher-order ranges in std.range:
padLeft(R, E)(R r, E e, size_t n)
if (isInputRange!R &&
hasLength!R &&
!is(CommonType!(ElementType!R, E) == void))
padRight(R, E)(R r, E e, size_t n)
is (isInputRange!R &&
!is(CommonType!(ElementType!R, E) == void))
padLeft returns a range that is padded on the left up to 'n' elements with 'e',
and padRight pads on the right.
Example:
int[] a = [1, 2, 3];
padLeft(a, 0, 5) == [0, 0, 1, 2, 3]
padRight(a, 0, 5) == [1, 2, 3, 0, 0]
Notes:
* If r.length >= n then neither add any padding, and just iterates r.
* padLeft requires hasLength, but padRight does not.
* If R is forward, then so will padLeft/Right
* If R is bidirectional, and hasLength, then so will padLeft/Right
* If R is random access, and hasLength, then so will padLeft/Right
* If R is infinite, padLeft/Right will return r and be type R.
--
More information about the Digitalmars-d-bugs
mailing list