countUntil to print all the index of a given string.
aberba
karabutaworld at gmail.com
Tue Feb 20 08:44:37 UTC 2018
On Sunday, 18 February 2018 at 15:23:14 UTC, Cym13 wrote:
> On Sunday, 18 February 2018 at 14:48:59 UTC, Cym13 wrote:
>> [...]
>
> Just thought of a much better/simpler solution for that last
> case that also doesn't force you to read all data (which might
> be impossible when dealing with infinite ranges):
>
> import std.range;
> import std.algorithm;
>
> a[]
> .enumerate // get tuples (index,
> value)
> .filter!(t => t[1] == "Test2") // keep only if value ==
> "Test2"
> .map!(t => t[0]) // keep only the index
> part
> .writeln;
>
> Completely lazy.
How does one detect an operation as lazy or not? Is the some
compile-time or runtime check for that?
My guess is by referring to the docs function signature.
More information about the Digitalmars-d-learn
mailing list