neither icon indicating copy to clipboard operation
neither copied to clipboard

Implement iterator api

Open nikhedonia opened this issue 8 years ago • 2 comments

A Maybe is a container like vector but has either 0 or 1 element. This would be convenient:

for(auto x : maybe(1) ) {
  std::cout << x << std::endl; // prints 1
} 

for(auto x : maybe<int>() ) {
  //loop not entered
} 

Functional maps should never have sideeffects. For sideeffects this way should be preferred.

nikhedonia avatar May 22 '17 10:05 nikhedonia

First of all: Congratulations for this awesome lib and also for the other projects, I really enjoyed the motivation for buckaroo and I hope to collaborate whenever possible!

Cool! I'm working on it. All right?

Just a question: Are we willing to make it possible to change wrapped value inside the loop? For instance: In the example, set x = 10?

If yes, it might make more sense to only allow iterations over auto const x

rvarago avatar Nov 05 '18 19:11 rvarago

Are we willing to make it possible to change wrapped value inside the loop?

I don't like the idea of mutations. So the answer is no.

it might make more sense to only allow iterations over auto const x

I think in c++ we cannot enforce the const when iterating by-value but we can enforce it for by-reference.

We also need to consider to overload begin/end for the case where the maybe is a rvalue (temporary) or contains a move only type eg. unique_ptr.

I'm not sure if for will extend the lifetime of a temporary until the end of the iteration. I guess a small test should reveal that quickly

First of all: Congratulations for this awesome lib and also for the other projects, I really enjoyed the motivation for buckaroo and I hope to collaborate whenever possible!

Thanks, this means a lot to us!

Cool! I'm working on it. All right?

Awesome!

nikhedonia avatar Nov 05 '18 19:11 nikhedonia