Skip to content

Commit

Permalink
Simplified SRTP for CancellableTaskResult & CancellableTaskValidation…
Browse files Browse the repository at this point in the history
… CE functions
  • Loading branch information
1eyewonder committed Jul 7, 2023
1 parent 3b5f579 commit d131b7b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 63 deletions.
33 changes: 12 additions & 21 deletions src/FsToolkit.ErrorHandling.IcedTasks/CancellableTaskResultCE.fs
Original file line number Diff line number Diff line change
Expand Up @@ -607,13 +607,10 @@ module CancellableTaskResultCE =
)

[<NoEagerConstraintApplication>]
member inline this.Source< ^TaskLike, ^Awaiter, 'T, 'Error
when ^TaskLike: (member GetAwaiter: unit -> ^Awaiter)
and ^Awaiter :> ICriticalNotifyCompletion
and ^Awaiter: (member get_IsCompleted: unit -> bool)
and ^Awaiter: (member GetResult: unit -> 'T)>
(t: ^TaskLike)
: CancellableTaskResult<'T, 'Error> =
member inline this.Source<'Awaitable, 'Awaiter, 'TResult, 'Error
when Awaitable<'Awaitable, 'Awaiter, 'TResult>>
(t: 'Awaitable)
: CancellableTaskResult<'TResult, 'Error> =

cancellableTask {
let! r = t
Expand All @@ -622,13 +619,10 @@ module CancellableTaskResultCE =


[<NoEagerConstraintApplication>]
member inline this.Source< ^TaskLike, ^Awaiter, 'T, 'Error
when ^TaskLike: (member GetAwaiter: unit -> ^Awaiter)
and ^Awaiter :> ICriticalNotifyCompletion
and ^Awaiter: (member get_IsCompleted: unit -> bool)
and ^Awaiter: (member GetResult: unit -> 'T)>
(t: unit -> ^TaskLike)
: CancellableTaskResult<'T, 'Error> =
member inline this.Source<'Awaitable, 'Awaiter, 'TResult, 'Error
when Awaitable<'Awaitable, 'Awaiter, 'TResult>>
(t: unit -> 'Awaitable)
: CancellableTaskResult<'TResult, 'Error> =

cancellableTask {
let! r = t
Expand All @@ -637,13 +631,10 @@ module CancellableTaskResultCE =


[<NoEagerConstraintApplication>]
member inline this.Source< ^TaskLike, ^Awaiter, 'T, 'Error
when ^TaskLike: (member GetAwaiter: unit -> ^Awaiter)
and ^Awaiter :> ICriticalNotifyCompletion
and ^Awaiter: (member get_IsCompleted: unit -> bool)
and ^Awaiter: (member GetResult: unit -> 'T)>
(t: CancellationToken -> ^TaskLike)
: CancellableTaskResult<'T, 'Error> =
member inline this.Source<'Awaitable, 'Awaiter, 'TResult, 'Error
when Awaitable<'Awaitable, 'Awaiter, 'TResult>>
(t: CancellationToken -> 'Awaitable)
: CancellableTaskResult<'TResult, 'Error> =

cancellableTask {
let! r = t
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ module CancellableTaskValidationCE =

type CancellableTaskValidationBuilderBase with


// https://github.com/dotnet/fsharp/discussions/15567
[<NoEagerConstraintApplication>]
member inline this.MergeSources<'TResult1, 'TResult2, ^Awaiter1, ^Awaiter2, 'Error
when ^Awaiter1 :> ICriticalNotifyCompletion
Expand Down Expand Up @@ -574,13 +574,9 @@ module CancellableTaskValidationCE =
(handler ct).GetAwaiter()
)


[<NoEagerConstraintApplication>]
member inline this.Source<'Awaitable, ^Awaiter, 'T, 'Error
when 'Awaitable: (member GetAwaiter: unit -> ^Awaiter)
and ^Awaiter :> ICriticalNotifyCompletion
and ^Awaiter: (member get_IsCompleted: unit -> bool)
and ^Awaiter: (member GetResult: unit -> 'T)>
member inline this.Source<'Awaitable, 'Awaiter, 'TResult
when Awaitable<'Awaitable, 'Awaiter, 'TResult>>
([<InlineIfLambda>] t: CancellationToken -> 'Awaitable)
=

Expand All @@ -593,11 +589,8 @@ module CancellableTaskValidationCE =


[<NoEagerConstraintApplication>]
member inline this.Source<'Awaitable, ^Awaiter, 'T, 'Error
when 'Awaitable: (member GetAwaiter: unit -> ^Awaiter)
and ^Awaiter :> ICriticalNotifyCompletion
and ^Awaiter: (member get_IsCompleted: unit -> bool)
and ^Awaiter: (member GetResult: unit -> 'T)>
member inline this.Source<'Awaitable, 'Awaiter, 'TResult
when Awaitable<'Awaitable, 'Awaiter, 'TResult>>
([<InlineIfLambda>] t: unit -> 'Awaitable)
=

Expand All @@ -610,11 +603,8 @@ module CancellableTaskValidationCE =


[<NoEagerConstraintApplication>]
member inline this.Source<'Awaitable, ^Awaiter, 'T, 'Error
when 'Awaitable: (member GetAwaiter: unit -> ^Awaiter)
and ^Awaiter :> ICriticalNotifyCompletion
and ^Awaiter: (member get_IsCompleted: unit -> bool)
and ^Awaiter: (member GetResult: unit -> 'T)>
member inline this.Source<'Awaitable, 'Awaiter, 'TResult
when Awaitable<'Awaitable, 'Awaiter, 'TResult>>
(t: 'Awaitable)
=

Expand All @@ -632,14 +622,7 @@ module CancellableTaskValidationCE =


[<NoEagerConstraintApplication>]
member inline this.Source<'Awaitable, ^Awaiter, 'T, 'Error
when 'Awaitable: (member GetAwaiter: unit -> ^Awaiter)
and ^Awaiter :> ICriticalNotifyCompletion
and ^Awaiter: (member get_IsCompleted: unit -> bool)
and ^Awaiter: (member GetResult: unit -> Result<'T, 'Error>)>
([<InlineIfLambda>] t: CancellationToken -> 'Awaitable)
=

member inline this.Source([<InlineIfLambda>] t: CancellationToken -> 'Awaitable) =
fun ct ->
(task {
let! r = t ct
Expand All @@ -649,14 +632,7 @@ module CancellableTaskValidationCE =


[<NoEagerConstraintApplication>]
member inline this.Source<'Awaitable, ^Awaiter, 'T, 'Error
when 'Awaitable: (member GetAwaiter: unit -> ^Awaiter)
and ^Awaiter :> ICriticalNotifyCompletion
and ^Awaiter: (member get_IsCompleted: unit -> bool)
and ^Awaiter: (member GetResult: unit -> Result<'T, 'Error>)>
([<InlineIfLambda>] t: unit -> 'Awaitable)
=

member inline this.Source([<InlineIfLambda>] t: unit -> 'Awaitable) =
fun (ct: CancellationToken) ->
(task {
let! r = t ()
Expand All @@ -666,14 +642,7 @@ module CancellableTaskValidationCE =


[<NoEagerConstraintApplication>]
member inline this.Source<'Awaitable, ^Awaiter, 'T, 'Error
when 'Awaitable: (member GetAwaiter: unit -> ^Awaiter)
and ^Awaiter :> ICriticalNotifyCompletion
and ^Awaiter: (member get_IsCompleted: unit -> bool)
and ^Awaiter: (member GetResult: unit -> Result<'T, 'Error>)>
(t: 'Awaitable)
=

member inline this.Source(t: 'Awaitable) =
fun (ct: CancellationToken) ->
(task {
let! r = t
Expand Down Expand Up @@ -724,7 +693,6 @@ module CancellableTaskValidationCE =
// Low priority extensions
type CancellableTaskValidationBuilderBase with


member inline this.Source(t: Task<'T>) =
fun (ct: CancellationToken) -> (Task.map Validation.ok t).GetAwaiter()

Expand Down

0 comments on commit d131b7b

Please sign in to comment.