22
33open System
44open System.Threading .Tasks
5- open FSharp.Control .Tasks .NonAffine .Unsafe
6- open FSharp.Control .Tasks .NonAffine
5+ open FSharp.Control .Tasks .Affine
76open Ply
87
98[<AutoOpen>]
@@ -13,15 +12,15 @@ module TaskResultCE =
1312
1413 member inline _.Return ( value : 'T )
1514 : Ply < Result < 'T , 'TError >> =
16- uply .Return ( result.Return value)
15+ task .Return ( result.Return value)
1716
1817 member inline _.ReturnFrom
1918 ( taskResult : Task < Result < 'T , 'TError >>)
2019 : Ply < Result < 'T , 'TError >> =
21- uply .ReturnFrom taskResult
20+ task .ReturnFrom taskResult
2221
2322 member inline _.Zero () : Ply < Result < unit , 'TError >> =
24- uply .Return <| result.Zero()
23+ task .Return <| result.Zero()
2524
2625 member inline _.Bind
2726 ( taskResult : Task < Result < 'T , 'TError >>,
@@ -30,66 +29,69 @@ module TaskResultCE =
3029 let binder ' r =
3130 match r with
3231 | Ok x -> binder x
33- | Error x -> uply .Return <| Error x
34- uply .Bind( taskResult, binder')
32+ | Error x -> task .Return <| Error x
33+ task .Bind( taskResult, binder')
3534
3635 member inline _.Delay
3736 ( generator : unit -> Ply < Result < 'T , 'TError >>) =
38- uply .Delay( generator)
37+ task .Delay( generator)
3938
4039 member inline _.Combine
4140 ( computation1 : Ply < Result < unit , 'TError >>,
4241 computation2 : unit -> Ply < Result < 'U , 'TError >>)
43- : Ply < Result < 'U , 'TError >> = uply {
44- match ! computation1 with
45- | Error e -> return Error e
46- | Ok _ -> return ! computation2()
47- }
42+ : Ply < Result < 'U , 'TError >> =
43+ task {
44+ match ! computation1 with
45+ | Error e -> return Error e
46+ | Ok _ -> return ! computation2()
47+ } |> task.ReturnFrom
4848
4949 member inline _.TryWith
5050 ( computation : unit -> Ply < Result < 'T , 'TError >>,
5151 handler : exn -> Ply < Result < 'T , 'TError >>) :
5252 Ply<Result<'T , 'TError>> =
53- uply .TryWith( computation, handler)
53+ task .TryWith( computation, handler)
5454
5555 member inline _.TryFinally
5656 ( computation : unit -> Ply < Result < 'T , 'TError >>,
5757 compensation : unit -> unit )
5858 : Ply < Result < 'T , 'TError >> =
59- uply .TryFinally( computation, compensation)
59+ task .TryFinally( computation, compensation)
6060
6161 member inline _.Using
6262 ( resource : 'T when 'T :> IDisposable ,
6363 binder : 'T -> Ply < Result < 'U , 'TError >>)
6464 : Ply < Result < 'U , 'TError >> =
65- uply .Using( resource, binder)
65+ task .Using( resource, binder)
6666
6767 member _.While
6868 ( guard : unit -> bool , computation : unit -> Ply < Result < unit , 'TError >>)
69- : Ply < Result < unit , 'TError >> = uply {
70- let mutable fin , result = false , Ok()
71- while not fin && guard() do
72- match ! computation() with
73- | Ok x -> x
74- | Error _ as e ->
75- result <- e
76- fin <- true
77- return result
78- }
69+ : Ply < Result < unit , 'TError >> =
70+ task {
71+ let mutable fin , result = false , Ok()
72+ while not fin && guard() do
73+ match ! computation() with
74+ | Ok x -> x
75+ | Error _ as e ->
76+ result <- e
77+ fin <- true
78+ return result
79+ } |> task.ReturnFrom
7980
8081 member _.For
8182 ( sequence : #seq<'T> , binder : 'T -> Ply < Result < unit , 'TError >>)
82- : Ply < Result < unit , 'TError >> = uply {
83- use enumerator = sequence.GetEnumerator()
84- let mutable fin , result = false , Ok()
85- while not fin && enumerator.MoveNext() do
86- match ! binder enumerator.Current with
87- | Ok x -> x
88- | Error _ as e ->
89- result <- e
90- fin <- true
91- return result
92- }
83+ : Ply < Result < unit , 'TError >> =
84+ task {
85+ use enumerator = sequence.GetEnumerator()
86+ let mutable fin , result = false , Ok()
87+ while not fin && enumerator.MoveNext() do
88+ match ! binder enumerator.Current with
89+ | Ok x -> x
90+ | Error _ as e ->
91+ result <- e
92+ fin <- true
93+ return result
94+ } |> task.ReturnFrom
9395
9496 member inline this.BindReturn ( x : Task < Result < 'T , 'U >>, f ) = this.Bind( x, fun x -> this.Return( f x))
9597 member inline _.MergeSources ( t1 : Task < Result < 'T , 'U >>, t2 : Task < Result < 'T1 , 'U >>) = TaskResult.zip t1 t2
0 commit comments