digitalmars.D.learn - join of range of ranges?
- bearophile (19/19) Sep 22 2013 In some cases I'd like to join a range of ranges in a single
- David Nadlinger (3/6) Sep 22 2013 std.algorithm.joiner, or am I missing something?
- bearophile (16/17) Sep 22 2013 Something like this? (It doesn't work yet):
- Peter Alexander (8/11) Sep 22 2013 The problem is that you are trying to map a range of range of
- bearophile (17/24) Sep 22 2013 I see, thank you. When I ask a question it seems my brain
- monarch_dodra (8/34) Sep 22 2013 Even "hello"c is supported actually :) It can make a difference
- bearophile (6/8) Sep 22 2013 OK. I have desired those char suffixes for years, so now I have
- Peter Alexander (4/10) Sep 22 2013 This could also be solved by having join return an array of the
In some cases I'd like to join a range of ranges in a single
array/string (I know here the inner map could be replaced by
something better, this code is just an example):
import std.algorithm: map;
import std.array: join, array;
void main() {
auto r1 = [1, 2]
.map!(x => [1, 2].map!(y => '*').array)
.join("_");
auto r2 = [1, 2]
.map!(x => [1, 2].map!(y => '*'))
.join("_");
}
The code works only if I add an 'array' inside, to turn it into a
range of arrays. Do you think it's right to ask as enhancement
for std.array.join to work with a range of ranges too, as in the
r2 case?
Bye,
bearophile
Sep 22 2013
On Sunday, 22 September 2013 at 14:26:14 UTC, bearophile wrote:In some cases I'd like to join a range of ranges in a single array/string (I know here the inner map could be replaced by something better, this code is just an example):std.algorithm.joiner, or am I missing something? David
Sep 22 2013
David Nadlinger:std.algorithm.joiner, or am I missing something?Something like this? (It doesn't work yet): import std.algorithm: map, joiner; import std.array: join, array; import std.string: text; void main() { string r1 = [1, 2] .map!(x => [1, 2].map!(y => '*').array) .join("_"); string r2 = [1, 2] .map!(x => [1, 2].map!(y => '*')) .joiner("_") .text; } Bye, bearophile
Sep 22 2013
On Sunday, 22 September 2013 at 14:26:14 UTC, bearophile wrote:
auto r2 = [1, 2]
.map!(x => [1, 2].map!(y => '*'))
.join("_");
The problem is that you are trying to map a range of range of
chars with a range of dchars.
auto r2 = [1, 2]
.map!(x => [1, 2].map!(y => cast(dchar)'*'))
.join("_");
This works.
I really wish character literals in D where always dchar.
Sep 22 2013
Peter Alexander:The problem is that you are trying to map a range of range of chars with a range of dchars. auto r2 = [1, 2] .map!(x => [1, 2].map!(y => cast(dchar)'*')) .join("_"); This works.I see, thank you. When I ask a question it seems my brain switches off a bit :-)I really wish character literals in D where always dchar.This is supported: void main() { auto s1 = "hello"w; auto s2 = "hello"d; } So, what about adding support for this? void main() { auto c1 = 'X'w; auto c2 = 'X'd; static assert(is(typeof(c1) == wchar)); static assert(is(typeof(c2) == dchar)); } Bye, bearophile
Sep 22 2013
On Sunday, 22 September 2013 at 20:27:01 UTC, bearophile wrote:Peter Alexander:Even "hello"c is supported actually :) It can make a difference if you *don't* want your string implicitly promoted on declaration. EG: dstring ds1 = "hello"; //Fine dstring ds2 = "hello"c; //Nope. As for allowing 'X'w, I think the rationale is that a cast will get you the same result (not so with string literals).The problem is that you are trying to map a range of range of chars with a range of dchars. auto r2 = [1, 2] .map!(x => [1, 2].map!(y => cast(dchar)'*')) .join("_"); This works.I see, thank you. When I ask a question it seems my brain switches off a bit :-)I really wish character literals in D where always dchar.This is supported: void main() { auto s1 = "hello"w; auto s2 = "hello"d; } So, what about adding support for this? void main() { auto c1 = 'X'w; auto c2 = 'X'd; static assert(is(typeof(c1) == wchar)); static assert(is(typeof(c2) == dchar)); } Bye, bearophile
Sep 22 2013
monarch_dodra:As for allowing 'X'w, I think the rationale is that a cast will get you the same result (not so with string literals).OK. I have desired those char suffixes for years, so now I have written an ER: http://d.puremagic.com/issues/show_bug.cgi?id=11103 Bye, bearophile
Sep 22 2013
On Sunday, 22 September 2013 at 18:13:39 UTC, Peter Alexander wrote:On Sunday, 22 September 2013 at 14:26:14 UTC, bearophile wrote:This could also be solved by having join return an array of the CommonType of the elements of both ranges.auto r2 = [1, 2] .map!(x => [1, 2].map!(y => '*')) .join("_");The problem is that you are trying to map a range of range of chars with a range of dchars.
Sep 22 2013









"bearophile" <bearophileHUGS lycos.com> 