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

Without statement for Results #9

Merged
merged 2 commits into from
Jan 12, 2022
Merged

Without statement for Results #9

merged 2 commits into from
Jan 12, 2022

Conversation

markspanbroek
Copy link
Member

@markspanbroek markspanbroek commented Jan 10, 2022

Supports without statements that provide access to the error in a Result.

Syntax:

  without value =? r, error:
    # use `error` to get the error from r
  # use value

@markspanbroek
Copy link
Member Author

An alternative syntax that was considered but not implemented:

  without (value, error) =? r:
    # use `error` to get the error from r
  # use value    

The reason for not going with that syntax is that it doesn't combine bindings very well:

  without ((value1, error1) =? r1) and ((value2, error2) =? r2):
    # is error1 set here?
    # is error2 set here?

@dryajov
Copy link

dryajov commented Jan 10, 2022

Nice! I like the syntax.

Is it possible to leave out the , error variable and have it behave same as the previous versions for backwards compatibility?

@emizzle
Copy link

emizzle commented Jan 11, 2022

LGTM, great job! Keen to know the answer to the above question as well, as I think it would be a good feature for backward compatibility.

@markspanbroek
Copy link
Member Author

No worries, this is a backwards compatible change. The version of without with two parameters (expression and body) is still there, and I intend to keep it because it's what you use when you're dealing with Options instead of Results.

@arnetheduck
Copy link

fwiw, a similar construct exists in the form of template valueOr, in Result itself - as part of the general refresh happening there, there's a corresponding template errorOr as well now - also, lmk if there are any primitives needed in Result itself that can help questionable - since we're mucking around with it, now is a good time to make those changes.

@markspanbroek
Copy link
Member Author

fwiw, a similar construct exists in the form of template valueOr, in Result itself

Yes, I've been able to make good use of valueOr in the |? operator.

as part of the general refresh happening there, there's a corresponding template errorOr as well now - also, lmk if there are any primitives needed in Result itself that can help questionable - since we're mucking around with it, now is a good time to make those changes.

Thanks, I appreciate that! There's one thing that I haven't been able to do, and that is provide a $ for Result[T, ref CatchableError]. If I remember correctly, it's related to a mixin $ that's somewhere in the Result library. I'll file an issue.

@markspanbroek
Copy link
Member Author

If I remember correctly, it's related to a mixin $ that's somewhere in the Result library. I'll file an issue.

I investigated the issue a bit further; turns out it didn't have anything to do with the mixin, but was triggered in a roundabout way by other test code. I filed an issue: arnetheduck/nim-results#21

@dryajov
Copy link

dryajov commented Jan 12, 2022

Anything blocking this from being merged?

@markspanbroek
Copy link
Member Author

Anything blocking this from being merged?

Not anymore, I found a nasty bug that needed fixing, but that's been dealt with in 15e514d. I'll make a new release shortly.

@markspanbroek markspanbroek merged commit a748d22 into main Jan 12, 2022
@markspanbroek markspanbroek deleted the without-result branch January 12, 2022 16:54
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

Successfully merging this pull request may close these issues.

4 participants