Skip to content

Commit 66a2757

Browse files
authored
Add ok and error helper functions to TaskResultOption and AsyncResultOption modules (#327)
1 parent fe3b446 commit 66a2757

File tree

5 files changed

+57
-0
lines changed

5 files changed

+57
-0
lines changed

gitbook/SUMMARY.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@
131131
* [apply](asyncResultOption/apply.md)
132132
* [bind](asyncResultOption/bind.md)
133133
* [Computation Expression](asyncResultOption/ce.md)
134+
* [error](asyncResultOption/error.md)
134135
* [ignore](asyncResultOption/ignore.md)
135136
* [map](asyncResultOption/map.md)
136137
* [map2](asyncResultOption/map2.md)
@@ -196,6 +197,7 @@
196197
* [apply](taskResultOption/apply.md)
197198
* [bind](taskResultOption/bind.md)
198199
* [Computation Expression](taskResultOption/ce.md)
200+
* [error](taskResultOption/error.md)
199201
* [ignore](taskResultOption/ignore.md)
200202
* [map](taskResultOption/map.md)
201203
* [map2](taskResultOption/map2.md)

gitbook/asyncResultOption/error.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
## AsyncResultOption.error
2+
3+
Namespace: `FsToolkit.ErrorHandling`
4+
5+
Lift an `'error` value into an `Async<Result<'ok option, 'error>>`
6+
7+
## Function Signature:
8+
9+
```fsharp
10+
'error -> Async<Result<'ok option, 'error>>
11+
```
12+
13+
## Examples
14+
15+
### Example 1
16+
17+
18+
```fsharp
19+
let result : Async<Result<int option, string>> =
20+
AsyncResultOption.error "Something bad happened"
21+
```
22+

gitbook/taskResultOption/error.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
## TaskResultOption.error
2+
3+
Namespace: `FsToolkit.ErrorHandling`
4+
5+
Lift an `'error` value into an `Task<Result<'ok option, 'error>>`
6+
7+
## Function Signature:
8+
9+
```fsharp
10+
'error -> Task<Result<'ok option, 'error>>
11+
```
12+
13+
## Examples
14+
15+
### Example 1
16+
17+
18+
```fsharp
19+
let result : Task<Result<int option, string>> =
20+
TaskResultOption.error "Something bad happened"
21+
```
22+

src/FsToolkit.ErrorHandling/AsyncResultOption.fs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ module AsyncResultOption =
2424
)
2525
input
2626

27+
let inline ok x =
28+
Ok(Some x)
29+
|> Async.singleton
30+
31+
let inline error x : Async<Result<'ok option, 'error>> =
32+
Error x
33+
|> Async.singleton
2734

2835
let inline map2
2936
([<InlineIfLambda>] mapper: 'okInput1 -> 'okInput2 -> 'okOutput)

src/FsToolkit.ErrorHandling/TaskResultOption.fs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ module TaskResultOption =
2323

2424
let inline singleton value = TaskResult.ok (Some value)
2525

26+
let inline ok x = singleton x
27+
28+
let inline error x : TaskResult<'ok option, 'error> = TaskResult.error x
29+
2630
let inline apply fTRO xTRO = map2 (fun f x -> f x) fTRO xTRO
2731

2832
/// Replaces the wrapped value with unit

0 commit comments

Comments
 (0)