Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: cannot uniquely infer foreach argument types #5

Closed
arjunadeltoso opened this issue Oct 6, 2014 · 4 comments
Closed

Error: cannot uniquely infer foreach argument types #5

arjunadeltoso opened this issue Oct 6, 2014 · 4 comments

Comments

@arjunadeltoso
Copy link

I have this code

auto redis_vals = this.redisdb.send("LRANGE", "vals", 0, -1);
writeln(redis_vals); // This prints [val_a, val_b]
foreach (val; redis_vals)
  writeln(val);

it doesn't compile because of Error: cannot uniquely infer foreach argument types.

I'm following the example at http://adilbaig.github.io/Tiny-Redis/

for(fruit; fruits)
  writeln(fruit);

and that also seems wrongly suggesting to use for instead of foreach.

@adilbaig
Copy link
Owner

adilbaig commented Oct 6, 2014

Hi @arjunadeltoso,

Thanks for reporting this. The foreach is implemented using opApply with the following signature :

int opApply(int delegate(ulong k, Response value) dg)

The key is required. For now, you'll need to implement your foreach loops as foreach(k, v; redis_vals) to get it to run. I'll move to a range based implementation in a future release.

And yes, the doc should say foreach

@arjunadeltoso
Copy link
Author

Thanks for the reply, yeah wasn't sure if

foreach(_, fruit; fruits)
  writeln(fruit)

was the correct approach or if I needed to overload opApply in response.d to take care of the values only iteration case (I've quickly tried it but with no success, just starting with D).

@adilbaig
Copy link
Owner

adilbaig commented Oct 6, 2014

That's correct. I've overloaded opApply in master to allow foreach without key declarations. I need to mull over making it into range before my next release. This one's a quick patch, but it closes the issue. I will close this ticket in my next release.

And the docs are fixed.

@adilbaig
Copy link
Owner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants