Is there an elegant way of making a Result eager instead of lazy?

simendsjo simendsjo at gmail.com
Tue Mar 20 10:40:37 PDT 2012


On Tue, 20 Mar 2012 18:36:46 +0100, ixid <nuaccount at gmail.com> wrote:

> I understand the point of lazy evaluation but I often want to use the  
> lazy algorithm library functions in an eager way. Other than looping  
> through them all which feels rather messy is there a good way of doing  
> this?
>
> Is there a reason not to allow the following to be automatically treated  
> eagerly or is there some kind of cast or conv way of doing it?
>
> 	int[] test1 = [1,2,3,4];
> 	int[] test2 = map!("a + a")(test1); //Eager, not allowed
>
> 	auto test3 = map!("a + a")(test1); //Lazy

std.array includes a method, array(), for doing exactly this:
int[] test2 = array(map!"a+a"(test1)); //eager


More information about the Digitalmars-d-learn mailing list