Skip to content

Commit eed5c0d

Browse files
cmeerenTheAngryByrd
authored andcommitted
Add explicit type parameters to ignore functions
1 parent 18491c8 commit eed5c0d

File tree

16 files changed

+101
-24
lines changed

16 files changed

+101
-24
lines changed

src/FsToolkit.ErrorHandling.JobResult/JobResult.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ module JobResult =
9797
result |> Job.bind (Result.either ok ifErrorFunc)
9898

9999
/// Replaces the wrapped value with unit
100-
let inline ignore jr = jr |> map ignore
100+
let inline ignore<'ok, 'error> (jr: Job<Result<'ok, 'error>>) = jr |> map ignore<'ok>
101101

102102
/// Returns the specified error if the job-wrapped value is false.
103103
let inline requireTrue error value =
@@ -166,7 +166,7 @@ module JobResult =
166166

167167
/// Same as defaultValue for a result where the Ok value is unit. The name
168168
/// describes better what is actually happening in this case.
169-
let inline ignoreError jobResult = defaultValue () jobResult
169+
let inline ignoreError<'error> (jobResult: Job<Result<unit, 'error>>) = defaultValue () jobResult
170170

171171
/// If the job-wrapped result is Ok, executes the function on the Ok value.
172172
/// Passes through the input value.

src/FsToolkit.ErrorHandling.JobResult/JobResultOption.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ module JobResultOption =
2424
let apply fJRO xJRO = map2 (fun f x -> f x) fJRO xJRO
2525

2626
/// Replaces the wrapped value with unit
27-
let inline ignore jro = jro |> map ignore
27+
let inline ignore<'a, 'b> (jro: Job<Result<'a option, 'b>>) = jro |> map ignore<'a>

src/FsToolkit.ErrorHandling.TaskResult/TaskResult.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ module TaskResult =
8888
result |> Task.bind (Result.either ok ifErrorFunc)
8989

9090
/// Replaces the wrapped value with unit
91-
let inline ignore tr = tr |> map ignore
91+
let inline ignore<'ok, 'error> (tr: Task<Result<'ok, 'error>>) = tr |> map ignore<'ok>
9292

9393
/// Returns the specified error if the task-wrapped value is false.
9494
let inline requireTrue error value =
@@ -158,7 +158,7 @@ module TaskResult =
158158

159159
/// Same as defaultValue for a result where the Ok value is unit. The name
160160
/// describes better what is actually happening in this case.
161-
let inline ignoreError taskResult = defaultValue () taskResult
161+
let inline ignoreError<'error> (taskResult: Task<Result<unit, 'error>>) = defaultValue () taskResult
162162

163163
/// If the task-wrapped result is Ok, executes the function on the Ok value.
164164
/// Passes through the input value.

src/FsToolkit.ErrorHandling.TaskResult/TaskResultOption.fs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
namespace FsToolkit.ErrorHandling
22

3+
open System.Threading.Tasks
4+
35

46
[<RequireQualifiedAccess>]
57
module TaskResultOption =
@@ -24,4 +26,4 @@ module TaskResultOption =
2426
let inline apply fTRO xTRO = map2 (fun f x -> f x) fTRO xTRO
2527

2628
/// Replaces the wrapped value with unit
27-
let inline ignore tro = tro |> map ignore
29+
let inline ignore<'ok, 'error> (tro: Task<Result<'ok option, 'error>>) = tro |> map ignore<'ok>

src/FsToolkit.ErrorHandling/AsyncResult.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ module AsyncResult =
132132
Async.bind (Result.either ok ifErrorFunc) input
133133

134134
/// Replaces the wrapped value with unit
135-
let inline ignore (value: Async<Result<'ok, 'error>>) : Async<Result<unit, 'error>> = value |> map ignore
135+
let inline ignore<'ok, 'error> (value: Async<Result<'ok, 'error>>) : Async<Result<unit, 'error>> = value |> map ignore<'ok>
136136

137137
/// Returns the specified error if the async-wrapped value is false.
138138
let inline requireTrue (error: 'error) (value: Async<bool>) : Async<Result<unit, 'error>> =
@@ -212,7 +212,7 @@ module AsyncResult =
212212

213213
/// Same as defaultValue for a result where the Ok value is unit. The name
214214
/// describes better what is actually happening in this case.
215-
let inline ignoreError (result: Async<Result<unit, 'error>>) : Async<unit> = defaultValue () result
215+
let inline ignoreError<'error> (result: Async<Result<unit, 'error>>) : Async<unit> = defaultValue () result
216216

217217
/// If the async-wrapped result is Ok, executes the function on the Ok value.
218218
/// Passes through the input value.

src/FsToolkit.ErrorHandling/AsyncResultOption.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,4 @@ module AsyncResultOption =
4545
map2 (fun f x -> f x) applier input
4646

4747
/// Replaces the wrapped value with unit
48-
let ignore (value: Async<Result<'ok option, 'error>>) : Async<Result<unit option, 'error>> = value |> map ignore
48+
let ignore<'ok, 'error> (value: Async<Result<'ok option, 'error>>) : Async<Result<unit option, 'error>> = value |> map ignore<'ok>

src/FsToolkit.ErrorHandling/Result.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ module Result =
160160
| Error e -> ifErrorFunc e
161161

162162
/// Replaces the wrapped value with unit
163-
let inline ignore (result: Result<'ok, 'error>) : Result<unit, 'error> =
163+
let inline ignore<'ok, 'error> (result: Result<'ok, 'error>) : Result<unit, 'error> =
164164
match result with
165165
| Ok _ -> Ok()
166166
| Error e -> Error e
@@ -256,7 +256,7 @@ module Result =
256256

257257
/// Same as defaultValue for a result where the Ok value is unit. The name
258258
/// describes better what is actually happening in this case.
259-
let inline ignoreError (result: Result<unit, 'error>) : unit = defaultValue () result
259+
let inline ignoreError<'error> (result: Result<unit, 'error>) : unit = defaultValue () result
260260

261261
/// If the result is Ok and the predicate returns true, executes the function
262262
/// on the Ok value. Passes through the input value.

src/FsToolkit.ErrorHandling/ResultOption.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ module ResultOption =
2323
let map3 f x y z = apply (map2 f x y) z
2424

2525
/// Replaces the wrapped value with unit
26-
let ignore ro = ro |> map ignore
26+
let ignore<'ok, 'error> (ro: Result<'ok option, 'error>) = ro |> map ignore<'ok>

tests/FsToolkit.ErrorHandling.JobResult.Tests/JobResult.fs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,15 @@ let ignoreTests =
228228
<| fun _ ->
229229
createPostFailure validCreatePostRequest
230230
|> JobResult.ignore
231-
|> Expect.hasJobErrorValueSync commonEx ]
231+
|> Expect.hasJobErrorValueSync commonEx
232+
233+
testCase "can call ignore without type parameters"
234+
<| fun _ ->
235+
ignore JobResult.ignore
236+
237+
testCase "can call ignore with type parameters"
238+
<| fun _ ->
239+
ignore<Job<Result<int, string>> -> Job<Result<unit, string>>> JobResult.ignore<int, string> ]
232240

233241
let err = "foobar"
234242
let toJob = Job.singleton
@@ -469,7 +477,13 @@ let ignoreErrorTests =
469477
<| fun _ -> Expect.hasJobValue () (JobResult.ignoreError (toJob (Ok())))
470478

471479
testCase "ignoreError returns the unit for Error"
472-
<| fun _ -> Expect.hasJobValue () (JobResult.ignoreError (toJob (Error err))) ]
480+
<| fun _ -> Expect.hasJobValue () (JobResult.ignoreError (toJob (Error err)))
481+
482+
testCase "Can call ignoreError without type parameter"
483+
<| fun _ -> ignore JobResult.ignoreError
484+
485+
testCase "Can call ignoreError with type parameter"
486+
<| fun _ -> ignore<Job<Result<unit, string>> -> Job<unit>> JobResult.ignoreError<string> ]
473487

474488
[<Tests>]
475489
let teeTests =

tests/FsToolkit.ErrorHandling.JobResult.Tests/JobResultOption.fs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,13 @@ let ignoreTests =
161161
<| fun _ ->
162162
getUserById (UserId(Guid.Empty))
163163
|> JobResultOption.ignore
164-
|> Expect.hasJobErrorValueSync "invalid user id" ]
164+
|> Expect.hasJobErrorValueSync "invalid user id"
165+
166+
testCase "can call ignore without type parameters"
167+
<| fun _ -> ignore JobResultOption.ignore
168+
169+
testCase "can call ignore with type parameters"
170+
<| fun _ -> ignore<Job<Result<int option, string>> -> Job<Result<unit option, string>>> JobResultOption.ignore<int, string> ]
165171

166172
[<Tests>]
167173
let computationExpressionTests =

0 commit comments

Comments
 (0)