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

Implement iterator api #2

Open
nikhedonia opened this issue May 22, 2017 · 2 comments
Open

Implement iterator api #2

nikhedonia opened this issue May 22, 2017 · 2 comments

Comments

@nikhedonia
Copy link
Contributor

nikhedonia commented May 22, 2017

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.

@rvarago
Copy link
Contributor

rvarago commented Nov 5, 2018

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

@nikhedonia
Copy link
Contributor Author

nikhedonia commented Nov 5, 2018

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 nikhedonia reopened this Dec 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants