Splitting a range into a range of tuples
Adam via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Jun 1 20:37:16 PDT 2015
> Everything is fine until I try to instantiate Tuples with my
> arrays. Then I get an error that says none of the overloads of
> the constructor are callable with these arguments. But I see
> this: http://dlang.org/phobos/std_typecons.html#.Tuple.this.2 ,
> which makes me think it should work. Am I doing something wrong?
Alright! I got what I wanted. Posting here for any fellow noobs
who may stumble across this and care what I was screwing up. It
looks like I accidentally gave a bad example, because I needed to
sort on the second elements ascending, not the first elements
descending. The lambdas I was feeding to sort were not working
because of the crazy types coming from the range methods, and it
turns out that I did not need tuples, since I could get a proper
sort from an array. This is what I ended up with (plus a couple
of filters that I'm omitting for clarity):
auto result =
input
.splitter(",")
.map!(v => v.splitter(" ")
.map!(a => a.to!(int))
.array()
)
.array()
.sort!("a[1]<b[1]");
Thanks Ali and Dennis for taking time to respond.
More information about the Digitalmars-d-learn
mailing list