Skip to content

Commit fd823eb

Browse files
1eyewonderTheAngryByrd
authored andcommitted
Simplified SRTP for CancellableTaskResult & CancellableTaskValidation CE functions
1 parent 97933c5 commit fd823eb

File tree

2 files changed

+22
-63
lines changed

2 files changed

+22
-63
lines changed

src/FsToolkit.ErrorHandling.IcedTasks/CancellableTaskResultCE.fs

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -607,13 +607,10 @@ module CancellableTaskResultCE =
607607
)
608608

609609
[<NoEagerConstraintApplication>]
610-
member inline this.Source< ^TaskLike, ^Awaiter, 'T, 'Error
611-
when ^TaskLike: (member GetAwaiter: unit -> ^Awaiter)
612-
and ^Awaiter :> ICriticalNotifyCompletion
613-
and ^Awaiter: (member get_IsCompleted: unit -> bool)
614-
and ^Awaiter: (member GetResult: unit -> 'T)>
615-
(t: ^TaskLike)
616-
: CancellableTaskResult<'T, 'Error> =
610+
member inline this.Source<'Awaitable, 'Awaiter, 'TResult, 'Error
611+
when Awaitable<'Awaitable, 'Awaiter, 'TResult>>
612+
(t: 'Awaitable)
613+
: CancellableTaskResult<'TResult, 'Error> =
617614

618615
cancellableTask {
619616
let! r = t
@@ -622,13 +619,10 @@ module CancellableTaskResultCE =
622619

623620

624621
[<NoEagerConstraintApplication>]
625-
member inline this.Source< ^TaskLike, ^Awaiter, 'T, 'Error
626-
when ^TaskLike: (member GetAwaiter: unit -> ^Awaiter)
627-
and ^Awaiter :> ICriticalNotifyCompletion
628-
and ^Awaiter: (member get_IsCompleted: unit -> bool)
629-
and ^Awaiter: (member GetResult: unit -> 'T)>
630-
(t: unit -> ^TaskLike)
631-
: CancellableTaskResult<'T, 'Error> =
622+
member inline this.Source<'Awaitable, 'Awaiter, 'TResult, 'Error
623+
when Awaitable<'Awaitable, 'Awaiter, 'TResult>>
624+
(t: unit -> 'Awaitable)
625+
: CancellableTaskResult<'TResult, 'Error> =
632626

633627
cancellableTask {
634628
let! r = t
@@ -637,13 +631,10 @@ module CancellableTaskResultCE =
637631

638632

639633
[<NoEagerConstraintApplication>]
640-
member inline this.Source< ^TaskLike, ^Awaiter, 'T, 'Error
641-
when ^TaskLike: (member GetAwaiter: unit -> ^Awaiter)
642-
and ^Awaiter :> ICriticalNotifyCompletion
643-
and ^Awaiter: (member get_IsCompleted: unit -> bool)
644-
and ^Awaiter: (member GetResult: unit -> 'T)>
645-
(t: CancellationToken -> ^TaskLike)
646-
: CancellableTaskResult<'T, 'Error> =
634+
member inline this.Source<'Awaitable, 'Awaiter, 'TResult, 'Error
635+
when Awaitable<'Awaitable, 'Awaiter, 'TResult>>
636+
(t: CancellationToken -> 'Awaitable)
637+
: CancellableTaskResult<'TResult, 'Error> =
647638

648639
cancellableTask {
649640
let! r = t

src/FsToolkit.ErrorHandling.IcedTasks/CancellableTaskValidationCE.fs

Lines changed: 10 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ module CancellableTaskValidationCE =
545545

546546
type CancellableTaskValidationBuilderBase with
547547

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

577-
578577
[<NoEagerConstraintApplication>]
579-
member inline this.Source<'Awaitable, ^Awaiter, 'T, 'Error
580-
when 'Awaitable: (member GetAwaiter: unit -> ^Awaiter)
581-
and ^Awaiter :> ICriticalNotifyCompletion
582-
and ^Awaiter: (member get_IsCompleted: unit -> bool)
583-
and ^Awaiter: (member GetResult: unit -> 'T)>
578+
member inline this.Source<'Awaitable, 'Awaiter, 'TResult
579+
when Awaitable<'Awaitable, 'Awaiter, 'TResult>>
584580
([<InlineIfLambda>] t: CancellationToken -> 'Awaitable)
585581
=
586582

@@ -593,11 +589,8 @@ module CancellableTaskValidationCE =
593589

594590

595591
[<NoEagerConstraintApplication>]
596-
member inline this.Source<'Awaitable, ^Awaiter, 'T, 'Error
597-
when 'Awaitable: (member GetAwaiter: unit -> ^Awaiter)
598-
and ^Awaiter :> ICriticalNotifyCompletion
599-
and ^Awaiter: (member get_IsCompleted: unit -> bool)
600-
and ^Awaiter: (member GetResult: unit -> 'T)>
592+
member inline this.Source<'Awaitable, 'Awaiter, 'TResult
593+
when Awaitable<'Awaitable, 'Awaiter, 'TResult>>
601594
([<InlineIfLambda>] t: unit -> 'Awaitable)
602595
=
603596

@@ -610,11 +603,8 @@ module CancellableTaskValidationCE =
610603

611604

612605
[<NoEagerConstraintApplication>]
613-
member inline this.Source<'Awaitable, ^Awaiter, 'T, 'Error
614-
when 'Awaitable: (member GetAwaiter: unit -> ^Awaiter)
615-
and ^Awaiter :> ICriticalNotifyCompletion
616-
and ^Awaiter: (member get_IsCompleted: unit -> bool)
617-
and ^Awaiter: (member GetResult: unit -> 'T)>
606+
member inline this.Source<'Awaitable, 'Awaiter, 'TResult
607+
when Awaitable<'Awaitable, 'Awaiter, 'TResult>>
618608
(t: 'Awaitable)
619609
=
620610

@@ -632,14 +622,7 @@ module CancellableTaskValidationCE =
632622

633623

634624
[<NoEagerConstraintApplication>]
635-
member inline this.Source<'Awaitable, ^Awaiter, 'T, 'Error
636-
when 'Awaitable: (member GetAwaiter: unit -> ^Awaiter)
637-
and ^Awaiter :> ICriticalNotifyCompletion
638-
and ^Awaiter: (member get_IsCompleted: unit -> bool)
639-
and ^Awaiter: (member GetResult: unit -> Result<'T, 'Error>)>
640-
([<InlineIfLambda>] t: CancellationToken -> 'Awaitable)
641-
=
642-
625+
member inline this.Source([<InlineIfLambda>] t: CancellationToken -> 'Awaitable) =
643626
fun ct ->
644627
(task {
645628
let! r = t ct
@@ -649,14 +632,7 @@ module CancellableTaskValidationCE =
649632

650633

651634
[<NoEagerConstraintApplication>]
652-
member inline this.Source<'Awaitable, ^Awaiter, 'T, 'Error
653-
when 'Awaitable: (member GetAwaiter: unit -> ^Awaiter)
654-
and ^Awaiter :> ICriticalNotifyCompletion
655-
and ^Awaiter: (member get_IsCompleted: unit -> bool)
656-
and ^Awaiter: (member GetResult: unit -> Result<'T, 'Error>)>
657-
([<InlineIfLambda>] t: unit -> 'Awaitable)
658-
=
659-
635+
member inline this.Source([<InlineIfLambda>] t: unit -> 'Awaitable) =
660636
fun (ct: CancellationToken) ->
661637
(task {
662638
let! r = t ()
@@ -666,14 +642,7 @@ module CancellableTaskValidationCE =
666642

667643

668644
[<NoEagerConstraintApplication>]
669-
member inline this.Source<'Awaitable, ^Awaiter, 'T, 'Error
670-
when 'Awaitable: (member GetAwaiter: unit -> ^Awaiter)
671-
and ^Awaiter :> ICriticalNotifyCompletion
672-
and ^Awaiter: (member get_IsCompleted: unit -> bool)
673-
and ^Awaiter: (member GetResult: unit -> Result<'T, 'Error>)>
674-
(t: 'Awaitable)
675-
=
676-
645+
member inline this.Source(t: 'Awaitable) =
677646
fun (ct: CancellationToken) ->
678647
(task {
679648
let! r = t
@@ -724,7 +693,6 @@ module CancellableTaskValidationCE =
724693
// Low priority extensions
725694
type CancellableTaskValidationBuilderBase with
726695

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

0 commit comments

Comments
 (0)