-
Notifications
You must be signed in to change notification settings - Fork 20
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
Allow results of match!
to be bound
#695
Comments
I see the issue, but I don't see any nice solutions to this. The possibility of just allowing one to write: let x =
match! x with | Some -> ... | None -> ... Just feels super dirty and just not right to me: it breaks the consistency of |
I run into this lately. Especially when I need to tag the result of a side effect. Here are the two ways to accomplish it that I could think of. Note: This is used in the effectful part of my code. Nested Async as mentioned above match effect with
| EnsurePositionTableExists ->
async {
let! result =
async {
match! Sql.write sqlConfig PositionTrackerSql.ensureExists with
| Ok () ->
return Ok ()
| Error ex ->
log.LogCritical("{@Effect} failed {@Ex}", effect, ex)
return Error ()
}
return PositionTableExists result
}
... Repeat tag in each branch match effect with
| EnsurePositionTableExists ->
async {
match! Sql.write sqlConfig PositionTrackerSql.ensureExists with
| Ok () ->
return PositionTableExists (Ok ())
| Error ex ->
log.LogCritical("{@Effect} failed {@Ex}", effect, ex)
return PositionTableExists (Error ())
}
... Each of these alternatives feels wasteful in some way. Although the nested async feels worse (and should perform worse unless optimized away). Here is how I wish I could express it: match effect with
| EnsurePositionTableExists ->
async {
match! Sql.write sqlConfig PositionTrackerSql.ensureExists with
| Ok () ->
Ok ()
| Error ex ->
log.LogCritical("{@Effect} failed {@Ex}", effect, ex)
Error ()
|> PositionTableExists
}
... But this includes non-related issues like eliminating gratuitous |
Closing this old issue |
Allow results of
match!
to be boundCurrently binding the results of
match!
reintroduces quite a bit of noise.Quoting from the conversation in the implementation:
Ideally, I think it would look like this:
let x = match! asyncX with Some x -> x | None -> fail()
Pros and Cons
The advantages of making this adjustment to F# are
match
The disadvantages of making this adjustment to F# are ...
Extra information
Estimated cost (XS, S, M, L, XL, XXL): S?
Related suggestions: #572
Affidavit (please submit!)
Please tick this by placing a cross in the box:
Please tick all that apply:
The text was updated successfully, but these errors were encountered: