Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 31 additions & 32 deletions gitbook/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
* [map](resultOption/map.md)
* [map2](resultOption/map2.md)
* [map3](resultOption/map3.md)
* [mapError](pr.md)
* [mapError](resultOption/mapError.md)
* [Operators](resultOption/operators.md)
* [zip](resultOption/zip.md)
* [zipError](resultOption/zipError.md)
Expand All @@ -96,8 +96,8 @@
* [mapError](asyncResult/mapError.md)
* [Operators](asyncResult/operators.md)
* [Other Functions](asyncResult/others.md)
* [zip](pr.md)
* [zipError](pr.md)
* [zip](asyncResult/zip.md)
* [zipError](asyncResult/zipError.md)
* List
* [traverseAsyncResultM](list/traverseAsyncResultM.md)
* [sequenceAsyncResultM](list/sequenceAsyncResultM.md)
Expand Down Expand Up @@ -139,35 +139,34 @@
* [ofResult](asyncResultOption/ofResult.md)

* Task
* [apply](pr.md)
* [bind](pr.md)
* [bindV](pr.md)
* [catch](pr.md)
* [Computation Expression](pr.md)
* [ignore](pr.md)
* [map](pr.md)
* [mapV](pr.md)
* [map2](pr.md)
* [map3](pr.md)
* [ofUnit](pr.md)
* [zip](pr.md)
* [apply](task/apply.md)
* [bind](task/bind.md)
* [bindV](task/bindV.md)
* [catch](task/catch.md)
* [Computation Expression](task/ce.md)
* [ignore](task/ignore.md)
* [map](task/map.md)
* [mapV](task/mapV.md)
* [map2](task/map2.md)
* [map3](task/map3.md)
* [zip](task/zip.md)
* Transforms
* [ofUnit](task/ofUnit.md)

* TaskOption
* [apply](pr.md)
* [bind](pr.md)
* [apply](taskOption/apply.md)
* [bind](taskOption/bind.md)
* [Computation Expression](taskOption/ce.md)
* [either](pr.md)
* [map](pr.md)
* [some](pr.md)
* [zip](pr.md)
* [either](taskOption/either.md)
* [map](taskOption/map.md)
* [Other Functions](taskOption/others.md)
* [zip](taskOption/zip.md)

* TaskResult
* [apply](taskResult/apply.md)
* [bind](taskResult/bind.md)
* [check](taskResult/check.md)
* [catch](pr.md)
* [catch](taskResult/catch.md)
* [Computation Expression](taskResult/ce.md)
* [ignore](taskResult/ignore.md)
* [map](taskResult/map.md)
Expand All @@ -177,8 +176,8 @@
* [Operators](taskResult/operators.md)
* [Other Functions](taskResult/others.md)
* [error](taskResult/error.md)
* [zip](pr.md)
* [zipError](pr.md)
* [zip](taskResult/zip.md)
* [zipError](taskResult/zipError.md)
* Lists
* [traverseTaskResultM](list/traverseTaskResultM.md)
* [sequenceTaskResultM](list/sequenceTaskResultM.md)
Expand All @@ -203,13 +202,13 @@
* [apply](validation/apply.md)
* [Computation Expression](validation/ce.md)
* [error](validation/error.md)
* [map](pr.md)
* [map](validation/map.md)
* [map2](validation/map2.md)
* [map3](validation/map3.md)
* [mapError](pr.md)
* [mapErrors](pr.md)
* [mapError](validation/mapError.md)
* [mapErrors](validation/mapErrors.md)
* [Operators](validation/operators.md)
* [zip](pr.md)
* [zip](validation/zip.md)
* Transforms
* [ofChoice](validation/ofChoice.md)
* [ofResult](validation/ofResult.md)
Expand All @@ -218,13 +217,13 @@
* [apply](asyncValidation/apply.md)
* [Computation Expression](asyncValidation/ce.md)
* [error](asyncValidation/error.md)
* [map](pr.md)
* [map](asyncValidation/map.md)
* [map2](asyncValidation/map2.md)
* [map3](asyncValidation/map3.md)
* [mapError](pr.md)
* [mapErrors](pr.md)
* [mapError](asyncValidation/mapError.md)
* [mapErrors](asyncValidation/mapErrors.md)
* [Operators](asyncValidation/operators.md)
* [zip](pr.md)
* [zip](asyncValidation/zip.md)
* Transforms
* [ofChoice](asyncValidation/ofChoice.md)
* [ofResult](asyncValidation/ofResult.md)
Expand Down
32 changes: 32 additions & 0 deletions gitbook/asyncResult/zip.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# AsyncResult.zip

Namespace: `FsToolkit.ErrorHandling`

## Function Signature

```fsharp
Async<Result<'leftOk, 'error>> -> Async<Result<'rightOk, 'error>> -> Async<Result<'leftOk * 'rightOk, 'error>>
```

## Examples

### Example 1

```fsharp
let result = AsyncResult.zip (AsyncResult.ok 1) (AsyncResult.ok 2)
// async { Ok (1, 2) }
```

### Example 2

```fsharp
let result = AsyncResult.zip (AsyncResult.ok 1) (AsyncResult.error "Bad")
// async { Error "Bad" }
```

### Example 3

```fsharp
let result = AsyncResult.zip (AsyncResult.error "Bad1") (AsyncResult.error "Bad2")
// async { Error "Bad1" }
```
32 changes: 32 additions & 0 deletions gitbook/asyncResult/zipError.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# AsyncResult.zipError

Namespace: `FsToolkit.ErrorHandling`

## Function Signature

```fsharp
Async<Result<'ok, 'leftError>> -> Async<Result<'ok, 'rightError>> -> Async<Result<'ok, 'leftError * 'rightError>>
```

## Examples

### Example 1

```fsharp
let result = AsyncResult.zipError (AsyncResult.ok 1) (AsyncResult.ok 2)
// async { Ok 1 }
```

### Example 2

```fsharp
let result = AsyncResult.zipError (AsyncResult.ok 1) (AsyncResult.error "Bad")
// async { Ok 1 }
```

### Example 3

```fsharp
let result = AsyncResult.zipError (AsyncResult.error "Bad1") (AsyncResult.error "Bad2")
// async { Error("Bad1", "Bad2") }
```
41 changes: 41 additions & 0 deletions gitbook/asyncValidation/map.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# AsyncValidation.map

Namespace: `FsToolkit.ErrorHandling`

`map` applies a transformation to the value inside an `AsyncValidation` if it represents a successful result (`Ok`). It allows you to perform a computation on the value while preserving the success/error status of the original `AsyncValidation`. If the original `AsyncValidation` is an `Error`, `map` does nothing and returns the same `Error` unchanged.

## Function Signature

```fsharp
('okInput -> 'okOutput) -> AsyncValidation<'okInput, 'error> -> AsyncValidation<'okOutput, 'error>
```

## Examples

Take the following functions for example

```fsharp
// string -> int
let remainingCharacters (prompt: string) =
280 - prompt.Length
```

### Example 1

```fsharp
let validation =
AsyncValidation.ok "foo" // AsyncValidation<string, string>
|> AsyncValidation.map remainingCharacters // AsyncValidation<int, string>

// async { Ok 277 }
```

### Example 2

```fsharp
let result =
AsyncValidation.error "bad things happened" // AsyncValidation<string, string>
|> AsyncValidation.map remainingCharacters // AsyncValidation<int, string>

// async { Error ["bad things happened"] }
```
44 changes: 44 additions & 0 deletions gitbook/asyncValidation/mapError.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# AsyncValidation.mapError

Namespace: `FsToolkit.ErrorHandling`

`mapError` takes an async validation and a normal function and returns a new async validation value based on the input error value and the function

## Function Signature

```fsharp
('errorInput -> 'errorOutput) -> AsyncValidation<'ok, 'errorInput>
-> AsyncValidation<'ok, 'errorOutput>
```

## Examples

Take the following functions for example

```fsharp
// string -> int
let getErrorCode (message: string) =
match message with
| "bad things happened" -> 1
| _ -> 0
```

### Example 1

```fsharp
let result =
AsyncValidation.ok "all good" // AsyncValidation<string, string>
|> AsyncValidation.mapError getErrorCode // AsyncValidation<string, int>

// async { Ok "all good" }
```

### Example 2

```fsharp
let result =
AsyncValidation.error "bad things happened" // AsyncValidation<string, string>
|> AsyncValidation.mapError getErrorCode // AsyncValidation<string, int>

// async { Error [1] }
```
44 changes: 44 additions & 0 deletions gitbook/asyncValidation/mapErrors.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# AsyncValidation.mapErrors

Namespace: `FsToolkit.ErrorHandling`

Similar to [AsyncValidation.mapError](../asyncValidation/mapError.md), except that the mapping function is passed the full list of errors, rather than each one individually.

## Function Signature

```fsharp
('errorInput list -> 'errorOutput list) -> AsyncValidation<'ok, 'errorInput>
-> AsyncValidation<'ok, 'errorOutput>
```

## Examples

Take the following functions for example

```fsharp
// string -> int
let getErrorCode (messages: string list) =
match messages |> List.tryFind ((=) "bad things happened") with
| Some _ -> [1]
| _ -> [0]
```

### Example 1

```fsharp
let result =
AsyncValidation.ok "all good" // AsyncValidation<string, string>
|> AsyncValidation.mapErrors getErrorCode // AsyncValidation<string, int>

// async { Ok "all good" }
```

### Example 2

```fsharp
let result : AsyncValidation<string, int> =
AsyncValidation.error "bad things happened" // AsyncValidation<string, string>
|> AsyncValidation.mapErrors getErrorCode // AsyncValidation<string, int>

// async { Error [1] }
```
32 changes: 32 additions & 0 deletions gitbook/asyncValidation/zip.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# AsyncValidation.zip

Namespace: `FsToolkit.ErrorHandling`

## Function Signature

```fsharp
AsyncValidation<'leftOk, 'error> -> AsyncValidation<'rightOk, 'error> -> AsyncValidation<'leftOk * 'rightOk, 'error>
```

## Examples

### Example 1

```fsharp
let result = AsyncValidation.zip (AsyncValidation.ok 1) (AsyncValidation.ok 2)
// async { Ok (1, 2) }
```

### Example 2

```fsharp
let result = AsyncValidation.zip (AsyncValidation.ok 1) (AsyncValidation.error "Bad")
// async { Error [ "Bad" ] }
```

### Example 3

```fsharp
let result = AsyncValidation.zip (AsyncValidation.error "Bad1") (AsyncValidation.error "Bad2")
// async { Error [ "Bad1"; "Bad2" ] }
```
7 changes: 3 additions & 4 deletions gitbook/result/map.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ Namespace: `FsToolkit.ErrorHandling`
## Function Signature

```fsharp
('okInput -> 'okOutput) -> Result<'okInput, 'error>
-> Result<'okOutput, 'error>
('okInput -> 'okOutput) -> Result<'okInput, 'error> -> Result<'okOutput, 'error>
```

## Examples
Expand All @@ -26,7 +25,7 @@ let remainingCharacters (prompt: string) =
```fsharp
let result =
Ok "foo" // Result<string, string>
|> ResultOption.map remainingCharacters // Result<int, string>
|> Result.map remainingCharacters // Result<int, string>

// Ok 277
```
Expand All @@ -36,7 +35,7 @@ let result =
```fsharp
let result =
Error "bad things happened" // Result<string, string>
|> ResultOption.map remainingCharacters // Result<int, string>
|> Result.map remainingCharacters // Result<int, string>

// Error "bad things happened"
```
Loading
Loading