diff --git a/src/FsToolkit.ErrorHandling.JobResult/JobOptionCE.fs b/src/FsToolkit.ErrorHandling.JobResult/JobOptionCE.fs index 4b78c074..dd105b0f 100644 --- a/src/FsToolkit.ErrorHandling.JobResult/JobOptionCE.fs +++ b/src/FsToolkit.ErrorHandling.JobResult/JobOptionCE.fs @@ -9,21 +9,21 @@ module JobOptionCE = type JobOptionBuilder() = - member __.Return (value: 'T) : Job> = + member __.Return (value: 'T) : Job<_ option> = job.Return <| option.Return value member __.ReturnFrom - (jobResult: Job>) - : Job> = + (jobResult: Job<_ option>) + : Job<_ option> = jobResult - member __.Zero () : Job> = + member __.Zero () : Job<_ option> = job.Return <| option.Zero () member __.Bind - (jobResult: Job>, - binder: 'T -> Job>) - : Job> = + (jobResult: Job<_ option>, + binder: 'T -> Job<_ option>) + : Job<_ option> = job { let! result = jobResult match result with @@ -32,61 +32,61 @@ module JobOptionCE = } member this.Bind - (taskResult: unit -> Task>, - binder: 'T -> Job>) - : Job> = + (taskResult: unit -> Task<_ option>, + binder: 'T -> Job<_ option>) + : Job<_ option> = this.Bind(Job.fromTask taskResult, binder) member __.Delay - (generator: unit -> Job>) - : Job> = + (generator: unit -> Job<_ option>) + : Job<_ option> = Job.delay generator member this.Combine - (computation1: Job>, - computation2: Job>) - : Job> = + (computation1: Job<_ option>, + computation2: Job<_ option>) + : Job<_ option> = this.Bind(computation1, fun () -> computation2) member __.TryWith - (computation: Job>, - handler: System.Exception -> Job>) - : Job> = + (computation: Job<_ option>, + handler: System.Exception -> Job<_ option>) + : Job<_ option> = Job.tryWith computation handler member __.TryWith - (computation: unit -> Job>, - handler: System.Exception -> Job>) - : Job> = + (computation: unit -> Job<_ option>, + handler: System.Exception -> Job<_ option>) + : Job<_ option> = Job.tryWithDelay computation handler member __.TryFinally - (computation: Job>, + (computation: Job<_ option>, compensation: unit -> unit) - : Job> = + : Job<_ option> = Job.tryFinallyFun computation compensation member __.TryFinally - (computation: unit -> Job>, + (computation: unit -> Job<_ option>, compensation: unit -> unit) - : Job> = + : Job<_ option> = Job.tryFinallyFunDelay computation compensation member __.Using (resource: 'T when 'T :> IDisposable, - binder: 'T -> Job>) - : Job> = + binder: 'T -> Job<_ option>) + : Job<_ option> = job.Using(resource, binder) member this.While - (guard: unit -> bool, computation: Job>) - : Job> = + (guard: unit -> bool, computation: Job<_ option>) + : Job<_ option> = if not <| guard () then this.Zero () else this.Bind(computation, fun () -> this.While (guard, computation)) member this.For - (sequence: #seq<'T>, binder: 'T -> Job>) - : Job> = + (sequence: #seq<'T>, binder: 'T -> Job<_ option>) + : Job<_ option> = this.Using(sequence.GetEnumerator (), fun enum -> this.While(enum.MoveNext, this.Delay(fun () -> binder enum.Current))) @@ -96,17 +96,17 @@ module JobOptionCE = /// /// See https://stackoverflow.com/questions/35286541/why-would-you-use-builder-source-in-a-custom-computation-expression-builder /// - member inline _.Source(job : Job>) : Job> = job + member inline _.Source(job : Job<_ option>) : Job<_ option> = job /// /// Method lets us transform data types into our internal representation. /// - member inline _.Source(async : Async>) : Job> = async |> Job.fromAsync + member inline _.Source(async : Async<_ option>) : Job<_ option> = async |> Job.fromAsync /// /// Method lets us transform data types into our internal representation. /// - member inline _.Source(task : Task>) : Job> = task |> Job.awaitTask + member inline _.Source(task : Task<_ option>) : Job<_ option> = task |> Job.awaitTask let jobOption = JobOptionBuilder() @@ -124,7 +124,7 @@ module JobOptionCEExtensions = /// /// Method lets us transform data types into our internal representation. /// - member inline __.Source(r: Option<'t>) = Job.singleton r + member inline __.Source(r: 't option) = Job.singleton r /// /// Method lets us transform data types into our internal representation. /// diff --git a/src/FsToolkit.ErrorHandling.TaskResult/TaskOptionCE.fs b/src/FsToolkit.ErrorHandling.TaskResult/TaskOptionCE.fs index 7156916a..0d52917f 100644 --- a/src/FsToolkit.ErrorHandling.TaskResult/TaskOptionCE.fs +++ b/src/FsToolkit.ErrorHandling.TaskResult/TaskOptionCE.fs @@ -12,21 +12,21 @@ module TaskOptionCE = member val SomeUnit = Some () member inline _.Return (value: 'T) - : Ply> = + : Ply<_ option> = uply.Return <| option.Return value member inline _.ReturnFrom - (taskResult: Task>) - : Ply> = + (taskResult: Task<_ option>) + : Ply<_ option> = uply.ReturnFrom taskResult - member inline _.Zero () : Ply> = + member inline _.Zero () : Ply<_ option> = uply.Return <| option.Zero() member inline _.Bind - (taskResult: Task>, - binder: 'T -> Ply>) - : Ply> = + (taskResult: Task<_ option>, + binder: 'T -> Ply<_ option>) + : Ply<_ option> = let binder' r = match r with | Some x -> binder x @@ -34,39 +34,39 @@ module TaskOptionCE = uply.Bind(taskResult, binder') member inline _.Delay - (generator: unit -> Ply>) = + (generator: unit -> Ply<_ option>) = uply.Delay(generator) member inline _.Combine - (computation1: Ply>, - computation2: unit -> Ply>) - : Ply> = uply { + (computation1: Ply<'T option>, + computation2: unit -> Ply<'U option>) + : Ply<'U option> = uply { match! computation1 with | None -> return None | Some _ -> return! computation2() } member inline _.TryWith - (computation: unit -> Ply>, - handler: exn -> Ply>) : - Ply> = + (computation: unit -> Ply<_ option>, + handler: exn -> Ply<_ option>) : + Ply<_ option> = uply.TryWith(computation, handler) member inline _.TryFinally - (computation: unit -> Ply>, + (computation: unit -> Ply<_ option>, compensation: unit -> unit) - : Ply> = + : Ply<_ option> = uply.TryFinally(computation, compensation) member inline _.Using (resource: 'T when 'T :> IDisposable, - binder: 'T -> Ply>) - : Ply> = + binder: 'T -> Ply<_ option>) + : Ply<_ option> = uply.Using(resource, binder) member _.While - (guard: unit -> bool, computation: unit -> Ply>) - : Ply> = uply { + (guard: unit -> bool, computation: unit -> Ply<'U option>) + : Ply<'U option> = uply { let mutable fin, result = false, None while not fin && guard() do match! computation() with @@ -79,8 +79,8 @@ module TaskOptionCE = } member _.For - (sequence: #seq<'T>, binder: 'T -> Ply>) - : Ply> = uply { + (sequence: #seq<'T>, binder: 'T -> Ply<'U option>) + : Ply<'U option> = uply { use enumerator = sequence.GetEnumerator() let mutable fin, result = false, None while not fin && enumerator.MoveNext() do @@ -93,30 +93,30 @@ module TaskOptionCE = return result } - member inline this.BindReturn(x: Task>, f) = this.Bind(x, fun x -> this.Return(f x)) - member inline _.MergeSources(t1: Task>, t2: Task>) = TaskOption.zip t1 t2 + member inline this.BindReturn(x: Task<'T option>, f) = this.Bind(x, fun x -> this.Return(f x)) + member inline _.MergeSources(t1: Task<'T option>, t2: Task<'T1 option>) = TaskOption.zip t1 t2 member inline _.Run(f : unit -> Ply<'m>) = task.Run f /// /// Method lets us transform data types into our internal representation. This is the identity method to recognize the self type. /// See https://stackoverflow.com/questions/35286541/why-would-you-use-builder-source-in-a-custom-computation-expression-builder /// - member inline _.Source(task : Task>) : Task> = task + member inline _.Source(task : Task<_ option>) : Task<_ option> = task /// /// Method lets us transform data types into our internal representation. /// - member inline _.Source(t : ValueTask>) : Task> = task { return! t } + member inline _.Source(t : ValueTask<_ option>) : Task<_ option> = task { return! t } /// /// Method lets us transform data types into our internal representation. /// - member inline _.Source(async : Async>) : Task> = async |> Async.StartAsTask + member inline _.Source(async : Async<_ option>) : Task<_ option> = async |> Async.StartAsTask /// /// Method lets us transform data types into our internal representation. /// - member inline _.Source(p : Ply>) : Task> = task { return! p } + member inline _.Source(p : Ply<_ option>) : Task<_ option> = task { return! p } let taskOption = TaskOptionBuilder() @@ -134,7 +134,7 @@ module TaskOptionCEExtensions = /// /// Method lets us transform data types into our internal representation. /// - member inline __.Source(r: Option<'t>) = Task.singleton r + member inline __.Source(r: 't option) = Task.singleton r /// /// Method lets us transform data types into our internal representation. diff --git a/src/FsToolkit.ErrorHandling/OptionCE.fs b/src/FsToolkit.ErrorHandling/OptionCE.fs index 1f1acf82..d7fc634c 100644 --- a/src/FsToolkit.ErrorHandling/OptionCE.fs +++ b/src/FsToolkit.ErrorHandling/OptionCE.fs @@ -8,15 +8,15 @@ module OptionCE = member inline _.ReturnFrom(m: 'T option) = m - member inline _.Bind(m : Option<'a>, f: 'a -> Option<'b>) = Option.bind f m + member inline _.Bind(m : 'a option, f: 'a -> 'b option) = Option.bind f m // Could not get it to work solely with Source. In loop cases it would potentially match the #seq overload and ask for type annotation - member this.Bind(m : 'a when 'a:null, f: 'a -> Option<'b>) = this.Bind(m |> Option.ofObj, f) + member this.Bind(m : 'a when 'a:null, f: 'a -> 'b option) = this.Bind(m |> Option.ofObj, f) member inline this.Zero() = this.Return () member inline _.Combine(m, f) = Option.bind f m - member inline this.Combine(m1 : Option<_>, m2 : Option<_>) = this.Bind(m1 , fun () -> m2) + member inline this.Combine(m1 : _ option, m2 : _ option) = this.Bind(m1 , fun () -> m2) member inline _.Delay(f: unit -> _) = f @@ -31,21 +31,21 @@ module OptionCE = finally compensation() member inline this.Using - (resource: 'T when 'T :> IDisposable, binder) : Option<_>= + (resource: 'T when 'T :> IDisposable, binder) : _ option= this.TryFinally ( (fun () -> binder resource), (fun () -> if not <| obj.ReferenceEquals(resource, null) then resource.Dispose ()) ) member this.While - (guard: unit -> bool, generator: unit -> Option<_>) - : Option<_> = + (guard: unit -> bool, generator: unit -> _ option) + : _ option = if not <| guard () then this.Zero () else this.Bind(this.Run generator, fun () -> this.While (guard, generator)) member inline this.For - (sequence: #seq<'T>, binder: 'T -> Option<_>) - : Option<_> = + (sequence: #seq<'T>, binder: 'T -> _ option) + : _ option = this.Using(sequence.GetEnumerator (), fun enum -> this.While(enum.MoveNext, this.Delay(fun () -> binder enum.Current))) @@ -59,7 +59,7 @@ module OptionCE = /// /// See https://stackoverflow.com/questions/35286541/why-would-you-use-builder-source-in-a-custom-computation-expression-builder /// - member inline _.Source(result : Option<_>) : Option<_> = result + member inline _.Source(result : _ option) : _ option = result let option = OptionBuilder() @@ -97,7 +97,7 @@ module OptionExtensions = // /// // /// Method lets us transform data types into our internal representation. // /// - member inline _.Source(nullable : Nullable<'a>) : Option<'a> = nullable |> Option.ofNullable + member inline _.Source(nullable : Nullable<'a>) : 'a option = nullable |> Option.ofNullable diff --git a/tests/FsToolkit.ErrorHandling.Tests/OptionCE.fs b/tests/FsToolkit.ErrorHandling.Tests/OptionCE.fs index 255e5874..9073276c 100644 --- a/tests/FsToolkit.ErrorHandling.Tests/OptionCE.fs +++ b/tests/FsToolkit.ErrorHandling.Tests/OptionCE.fs @@ -15,7 +15,7 @@ let makeDisposable () = with member this.Dispose() = () } -// type Option<'a> = | Some of 'a | None +// type 'a option = | Some of 'a | None let ceTests = testList "CE Tests" [