-
Notifications
You must be signed in to change notification settings - Fork 21
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
Support do! ... and! ... #1359
Comments
Note that it I think this should be able to be combined with let getOrderSummary user category =
validation {
do! user.CanShowOrders |> Result.requireTrue UnauthorizedOrderSummary
and! user.AllowedCategories.Contains category |> Result.requireTrue UnauthorizedCategory
and! foo = user.Foo |> Result.requireSome MissingFoo
return getOrderSummary' category foo
} This makes me slightly doubt my suggestion. |
Isn't it already supported? https://learn.microsoft.com/en-us/dotnet/fsharp/language-reference/computation-expressions#and |
|
For what it's worth, this is what the original RFC for
The comment about I would personally normally try to use a "parse, don't validate" approach where possible — in one of the codebases I'm thinking of, the deserialization already had a manual mapping step anyway, and the "validation" could have just been done there as (applicative) "parsing" to begin with. The number of lines of code for validating ( And even when there is a good reason not to use the "parse, don't validate" approach (e.g., perf overhead, DTOs known to be always identical to domain types for the lifetime of the codebase, etc.), I personally think that the existing
Indeed, |
I think this is generally a good suggestion. Another use case may be where people want to create a bunch of tasks and execute them in parallel (this has been suggested for I'd like to propose, however, to use the |
As a variant proposal, |
I propose we add support for
do! ... and! ...
in computation expressions.Consider this imagined example using
validation
from FsToolkit.ErrorHandling (likeresult
, but with applicative combination of a list of errors):The existing way of approaching this problem in F# is using
let! _ = ... and! _ = ...
:Pros and Cons
The advantages of making this adjustment to F# are more natural/intuitive syntax.
The disadvantages of making this adjustment to F# are none, as far as I can see. This seems to me to be an intuitive syntax. YMMV.
Extra information
Estimated cost (XS, S, M, L, XL, XXL): Don't really know. S/M?
Related suggestions: (put links to related suggestions here)
Affidavit (please submit!)
Please tick these items by placing a cross in the box:
Please tick all that apply:
For Readers
If you would like to see this issue implemented, please click the 👍 emoji on this issue. These counts are used to generally order the suggestions by engagement.
The text was updated successfully, but these errors were encountered: