You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In Example 1, we collected all the error messages. But what if we wanted to stop on the first error? One way to do this is to make use of the `result` computation expression instead of using infix operators from `Result` module.
let validateCreatePostRequest (dto : CreatePostRequestDto) = result {
149
154
let! t = Result.tryCreate "tweet" dto.Tweet
150
155
let! lat = Result.tryCreate "latitude" dto.Location.Latitude
@@ -158,23 +163,26 @@ let validateCreatePostRequest (dto : CreatePostRequestDto) = result {
158
163
In the examples above, we assume that a location is always required for creating a post. Let's assume that the requirement is changed and now the location is optional:
159
164
160
165
```fsharp
161
-
type CreatePostRequest = {
162
-
Tweet : Tweet
163
-
Location : Location option
164
-
}
165
-
166
166
type CreatePostRequestDto = {
167
167
Tweet : string
168
168
Location : LocationDto option
169
169
}
170
170
171
+
type CreatePostRequest = {
172
+
Tweet : Tweet
173
+
Location : Location option
174
+
}
175
+
171
176
let createPostRequest location tweet =
172
177
{Tweet = tweet; Location = location}
173
178
```
174
179
175
180
Then `validateCreatePostRequest` can be rewritten using the [Option.traverseResult](../option/traverseResult.md) function as below:
0 commit comments