Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
April 26, 2015 Literan/constant ranges | ||||
---|---|---|---|---|
| ||||
I find myself using these a lot. I hacked them together because I couldn't find anything equally simple in the std library: https://gist.github.com/TurkeyMan/1f551bc5a0d2cec8af2e The question is, is there already a proper/better way to do this? |
April 26, 2015 Re: Literan/constant ranges | ||||
---|---|---|---|---|
| ||||
Posted in reply to Manu | On Sunday, 26 April 2015 at 04:59:48 UTC, Manu wrote:
> I find myself using these a lot. I hacked them together because I
> couldn't find anything equally simple in the std library:
>
> https://gist.github.com/TurkeyMan/1f551bc5a0d2cec8af2e
>
> The question is, is there already a proper/better way to do this?
std.range.repeat?
|
April 26, 2015 Re: Literan/constant ranges | ||||
---|---|---|---|---|
| ||||
Posted in reply to Manu | On Sunday, 26 April 2015 at 04:59:48 UTC, Manu wrote: > I find myself using these a lot. I hacked them together because I > couldn't find anything equally simple in the std library: > > https://gist.github.com/TurkeyMan/1f551bc5a0d2cec8af2e > > The question is, is there already a proper/better way to do this? LiteralRange looks quite similar to std.range.repeat[1], and ConstantRange looks similar to std.range.only[2]. 1: http://dlang.org/phobos/std_range.html#repeat 2: http://dlang.org/phobos/std_range.html#only |
April 26, 2015 Re: Literan/constant ranges | ||||
---|---|---|---|---|
| ||||
Posted in reply to Meta | Man, I suck so hard at navigating the std library! Practically nothing
is named anything I expect or am familiar with >_<
It shouldn't be easier to write my own than to find what I want in the lib.
There are some differences though; repeat() is not a literal, and
repeats infinitely, which means you need to conjoin take(n), which
leads to a long and less-readable line.
I wonder if there is any value to a literal/variable distinction as I have?
On 26 April 2015 at 15:05, Meta via Digitalmars-d <digitalmars-d@puremagic.com> wrote:
> On Sunday, 26 April 2015 at 04:59:48 UTC, Manu wrote:
>>
>> I find myself using these a lot. I hacked them together because I couldn't find anything equally simple in the std library:
>>
>> https://gist.github.com/TurkeyMan/1f551bc5a0d2cec8af2e
>>
>> The question is, is there already a proper/better way to do this?
>
>
> LiteralRange looks quite similar to std.range.repeat[1], and ConstantRange looks similar to std.range.only[2].
>
> 1: http://dlang.org/phobos/std_range.html#repeat
> 2: http://dlang.org/phobos/std_range.html#only
|
April 26, 2015 Re: Literan/constant ranges | ||||
---|---|---|---|---|
| ||||
Posted in reply to Manu | On Sunday, 26 April 2015 at 06:43:22 UTC, Manu wrote:
> Man, I suck so hard at navigating the std library! Practically nothing
> is named anything I expect or am familiar with >_<
> It shouldn't be easier to write my own than to find what I want in the lib.
>
> There are some differences though; repeat() is not a literal, and
> repeats infinitely, which means you need to conjoin take(n), which
> leads to a long and less-readable line.
There is a second overload.
|
Copyright © 1999-2021 by the D Language Foundation