How to use `format` to repeat a character
ag0aep6g via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Jul 11 03:00:13 PDT 2016
On 07/11/2016 11:31 AM, Ali Çehreli wrote:
> // Another one that combines multiple range algorithms
> import std.range : iota;
> import std.algorithm : map;
> assert(7.iota.map!(i => i % 2 ? '=' : '-').equal("-=-=-=-"));
An alternative without those scary modulo and ternary operators, just
because I think it's cute:
import std.range: repeat, roundRobin, take;
import std.algorithm: equal;
assert(roundRobin(repeat('-'), repeat('=')).take(7).equal("-=-=-=-"));
More information about the Digitalmars-d-learn
mailing list