Skip to content

Commit c3dbb5f

Browse files
njlrTheAngryByrd
authored andcommitted
* Swaps vaid ranges for lat-lng
1 parent f904346 commit c3dbb5f

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

gitbook/validation/tryCreate.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## Result.tryCreate
1+
## Result.tryCreate
22

33
Namespace: `FsToolkit.ErrorHandling`
44

@@ -28,10 +28,10 @@ type Longitude = private Longitude of float with
2828
2929
// float -> Result<Longitude, string>
3030
static member TryCreate (lng : float) =
31-
if lng >= -90. && lng <= 90. then
31+
if lng >= -180. && lng <= 180. then
3232
Ok (Longitude lng)
3333
else
34-
sprintf "%A is a invalid longitude value" lng |> Error
34+
sprintf "%A is a invalid longitude value" lng |> Error
3535
```
3636

3737
Let's assume that we have few more similar types as below
@@ -42,10 +42,10 @@ type Longitude = private Longitude of float with
4242
let (Longitude lng) = this
4343
lng
4444
static member TryCreate (lng : float) =
45-
if lng > -90. && lng < 90. then
45+
if lng > -180. && lng < 180. then
4646
Ok (Longitude lng)
4747
else
48-
sprintf "%A is a invalid longitude value" lng |> Error
48+
sprintf "%A is a invalid longitude value" lng |> Error
4949
5050
type Tweet = private Tweet of string with
5151
member this.Value =
@@ -100,7 +100,7 @@ type CreatePostRequestDto = {
100100
We can then do validation using `Result.tryResult` and the [`Validation` infix operators](../validation/operators.md) as below:
101101

102102
```fsharp
103-
open FsToolkit.ErrorHandling.Operator.Validation
103+
open FsToolkit.ErrorHandling.Operator.Validation
104104
105105
// CreatePostRequestDto -> Result<CreatePostRequest, (string * string) list>
106106
let validateCreatePostRequest (dto : CreatePostRequestDto) =
@@ -186,10 +186,10 @@ let validateCreatePostRequest (dto : CreatePostRequestDto) =
186186
<*^> Result.tryCreate "tweet" dto.Tweet
187187
```
188188

189-
Note: We are using the `<!>` operator in the `validateCreatePostRequest` instead of `<!^>` operator as the right side result is returning a list of errors (`Result<Location option, (string * string) list>`).
189+
Note: We are using the `<!>` operator in the `validateCreatePostRequest` instead of `<!^>` operator as the right side result is returning a list of errors (`Result<Location option, (string * string) list>`).
190190

191191
```fsharp
192-
validateCreatePostRequest
192+
validateCreatePostRequest
193193
{Tweet = ""; Location = Some {Latitude = 300.; Longitude = 400.}}
194194
// Error
195195
// [("latitude", "300.0 is a invalid latitude value")

0 commit comments

Comments
 (0)