-
Notifications
You must be signed in to change notification settings - Fork 231
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
Add optional.unwrap() / .unwrapOpt() function #1103
Conversation
@seirl we ended up choosing a different name for this feature, with I think the behavior is the same, but would you mind taking a look and updating to match? |
Ah, okay. I think it might hinder readability in our case, because we usually have long chains of map/filter/flatten/elideOpt/all/exists/.... |
Hi @seirl, my impression is that the chains will continue to work just fine, but you'd probably just want to wrap the end result into an |
The problem is that mixing up prefix and postfix is less readable in long processing chains:
vs:
(which I had to re-read 3 times to make sure that it was correctly parenthesized) So my preference is for postfix because it's the most consistent, but we could also have both for backwards compatibility (one prefix and one postfix, maybe |
Consider, for a moment, that the expression My impression of what you're actually going to have to support is something more like the following: optional.unwrap(mylist).sortBy(foo, foo.bar).filter(foo, foo.value < 42) That is to say, I expect the |
Right, sorry! Here is a more realistic example partially taken from our codebase:
|
@seirl thank you, that helps me better understand. In that case, to be consistent, let's introduce |
This function takes a list of optional values and only returns the non-none values from the list, skipping the none values, and returning a list of the unwrapped values directly.
@TristonianJones PTAL :-) |
This function takes a list of optional values and only returns the non-none values from the list, skipping the none values, and returning a list of the unwrapped values directly.