Skip to content

Commit

Permalink
Replace all "Option<_>" annotations with "_ option"
Browse files Browse the repository at this point in the history
  • Loading branch information
cmeeren authored and njlr committed Nov 23, 2021
1 parent 9ee1d86 commit bf89b42
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 75 deletions.
70 changes: 35 additions & 35 deletions src/FsToolkit.ErrorHandling.JobResult/JobOptionCE.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@ module JobOptionCE =

type JobOptionBuilder() =

member __.Return (value: 'T) : Job<Option<_>> =
member __.Return (value: 'T) : Job<_ option> =
job.Return <| option.Return value

member __.ReturnFrom
(jobResult: Job<Option<_>>)
: Job<Option<_>> =
(jobResult: Job<_ option>)
: Job<_ option> =
jobResult

member __.Zero () : Job<Option<_>> =
member __.Zero () : Job<_ option> =
job.Return <| option.Zero ()

member __.Bind
(jobResult: Job<Option<_>>,
binder: 'T -> Job<Option<_>>)
: Job<Option<_>> =
(jobResult: Job<_ option>,
binder: 'T -> Job<_ option>)
: Job<_ option> =
job {
let! result = jobResult
match result with
Expand All @@ -32,61 +32,61 @@ module JobOptionCE =
}

member this.Bind
(taskResult: unit -> Task<Option<_>>,
binder: 'T -> Job<Option<_>>)
: Job<Option<_>> =
(taskResult: unit -> Task<_ option>,
binder: 'T -> Job<_ option>)
: Job<_ option> =
this.Bind(Job.fromTask taskResult, binder)

member __.Delay
(generator: unit -> Job<Option<_>>)
: Job<Option<_>> =
(generator: unit -> Job<_ option>)
: Job<_ option> =
Job.delay generator

member this.Combine
(computation1: Job<Option<_>>,
computation2: Job<Option<_>>)
: Job<Option<_>> =
(computation1: Job<_ option>,
computation2: Job<_ option>)
: Job<_ option> =
this.Bind(computation1, fun () -> computation2)

member __.TryWith
(computation: Job<Option<_>>,
handler: System.Exception -> Job<Option<_>>)
: Job<Option<_>> =
(computation: Job<_ option>,
handler: System.Exception -> Job<_ option>)
: Job<_ option> =
Job.tryWith computation handler

member __.TryWith
(computation: unit -> Job<Option<_>>,
handler: System.Exception -> Job<Option<_>>)
: Job<Option<_>> =
(computation: unit -> Job<_ option>,
handler: System.Exception -> Job<_ option>)
: Job<_ option> =
Job.tryWithDelay computation handler

member __.TryFinally
(computation: Job<Option<_>>,
(computation: Job<_ option>,
compensation: unit -> unit)
: Job<Option<_>> =
: Job<_ option> =
Job.tryFinallyFun computation compensation

member __.TryFinally
(computation: unit -> Job<Option<_>>,
(computation: unit -> Job<_ option>,
compensation: unit -> unit)
: Job<Option<_>> =
: Job<_ option> =
Job.tryFinallyFunDelay computation compensation

member __.Using
(resource: 'T when 'T :> IDisposable,
binder: 'T -> Job<Option<_>>)
: Job<Option<_>> =
binder: 'T -> Job<_ option>)
: Job<_ option> =
job.Using(resource, binder)

member this.While
(guard: unit -> bool, computation: Job<Option<_>>)
: Job<Option<_>> =
(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<Option<_>>)
: Job<Option<_>> =
(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)))
Expand All @@ -96,17 +96,17 @@ module JobOptionCE =
///
/// See https://stackoverflow.com/questions/35286541/why-would-you-use-builder-source-in-a-custom-computation-expression-builder
/// </summary>
member inline _.Source(job : Job<Option<_>>) : Job<Option<_>> = job
member inline _.Source(job : Job<_ option>) : Job<_ option> = job

/// <summary>
/// Method lets us transform data types into our internal representation.
/// </summary>
member inline _.Source(async : Async<Option<_>>) : Job<Option<_>> = async |> Job.fromAsync
member inline _.Source(async : Async<_ option>) : Job<_ option> = async |> Job.fromAsync

/// <summary>
/// Method lets us transform data types into our internal representation.
/// </summary>
member inline _.Source(task : Task<Option<_>>) : Job<Option<_>> = task |> Job.awaitTask
member inline _.Source(task : Task<_ option>) : Job<_ option> = task |> Job.awaitTask

let jobOption = JobOptionBuilder()

Expand All @@ -124,7 +124,7 @@ module JobOptionCEExtensions =
/// <summary>
/// Method lets us transform data types into our internal representation.
/// </summary>
member inline __.Source(r: Option<'t>) = Job.singleton r
member inline __.Source(r: 't option) = Job.singleton r
/// <summary>
/// Method lets us transform data types into our internal representation.
/// </summary>
Expand Down
58 changes: 29 additions & 29 deletions src/FsToolkit.ErrorHandling.TaskResult/TaskOptionCE.fs
Original file line number Diff line number Diff line change
Expand Up @@ -12,61 +12,61 @@ module TaskOptionCE =
member val SomeUnit = Some ()

member inline _.Return (value: 'T)
: Ply<Option<_>> =
: Ply<_ option> =
uply.Return <| option.Return value

member inline _.ReturnFrom
(taskResult: Task<Option<_>>)
: Ply<Option<_>> =
(taskResult: Task<_ option>)
: Ply<_ option> =
uply.ReturnFrom taskResult

member inline _.Zero () : Ply<Option<_>> =
member inline _.Zero () : Ply<_ option> =
uply.Return <| option.Zero()

member inline _.Bind
(taskResult: Task<Option<_>>,
binder: 'T -> Ply<Option<_>>)
: Ply<Option<_>> =
(taskResult: Task<_ option>,
binder: 'T -> Ply<_ option>)
: Ply<_ option> =
let binder' r =
match r with
| Some x -> binder x
| None -> uply.Return None
uply.Bind(taskResult, binder')

member inline _.Delay
(generator: unit -> Ply<Option<_>>) =
(generator: unit -> Ply<_ option>) =
uply.Delay(generator)

member inline _.Combine
(computation1: Ply<Option<'T>>,
computation2: unit -> Ply<Option<'U>>)
: Ply<Option<'U>> = 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<Option<_>>,
handler: exn -> Ply<Option<_>>) :
Ply<Option<_>> =
(computation: unit -> Ply<_ option>,
handler: exn -> Ply<_ option>) :
Ply<_ option> =
uply.TryWith(computation, handler)

member inline _.TryFinally
(computation: unit -> Ply<Option<_>>,
(computation: unit -> Ply<_ option>,
compensation: unit -> unit)
: Ply<Option<_>> =
: Ply<_ option> =
uply.TryFinally(computation, compensation)

member inline _.Using
(resource: 'T when 'T :> IDisposable,
binder: 'T -> Ply<Option<_>>)
: Ply<Option<_>> =
binder: 'T -> Ply<_ option>)
: Ply<_ option> =
uply.Using(resource, binder)

member _.While
(guard: unit -> bool, computation: unit -> Ply<Option<'U>>)
: Ply<Option<'U>> = 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
Expand All @@ -79,8 +79,8 @@ module TaskOptionCE =
}

member _.For
(sequence: #seq<'T>, binder: 'T -> Ply<Option<'U>>)
: Ply<Option<'U>> = 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
Expand All @@ -93,30 +93,30 @@ module TaskOptionCE =
return result
}

member inline this.BindReturn(x: Task<Option<'T>>, f) = this.Bind(x, fun x -> this.Return(f x))
member inline _.MergeSources(t1: Task<Option<'T>>, t2: Task<Option<'T1>>) = 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

/// <summary>
/// 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
/// </summary>
member inline _.Source(task : Task<Option<_>>) : Task<Option<_>> = task
member inline _.Source(task : Task<_ option>) : Task<_ option> = task

/// <summary>
/// Method lets us transform data types into our internal representation.
/// </summary>
member inline _.Source(t : ValueTask<Option<_>>) : Task<Option<_>> = task { return! t }
member inline _.Source(t : ValueTask<_ option>) : Task<_ option> = task { return! t }

/// <summary>
/// Method lets us transform data types into our internal representation.
/// </summary>
member inline _.Source(async : Async<Option<_>>) : Task<Option<_>> = async |> Async.StartAsTask
member inline _.Source(async : Async<_ option>) : Task<_ option> = async |> Async.StartAsTask

/// <summary>
/// Method lets us transform data types into our internal representation.
/// </summary>
member inline _.Source(p : Ply<Option<_>>) : Task<Option<_>> = task { return! p }
member inline _.Source(p : Ply<_ option>) : Task<_ option> = task { return! p }

let taskOption = TaskOptionBuilder()

Expand All @@ -134,7 +134,7 @@ module TaskOptionCEExtensions =
/// <summary>
/// Method lets us transform data types into our internal representation.
/// </summary>
member inline __.Source(r: Option<'t>) = Task.singleton r
member inline __.Source(r: 't option) = Task.singleton r

/// <summary>
/// Method lets us transform data types into our internal representation.
Expand Down
20 changes: 10 additions & 10 deletions src/FsToolkit.ErrorHandling/OptionCE.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)))
Expand All @@ -59,7 +59,7 @@ module OptionCE =
///
/// See https://stackoverflow.com/questions/35286541/why-would-you-use-builder-source-in-a-custom-computation-expression-builder
/// </summary>
member inline _.Source(result : Option<_>) : Option<_> = result
member inline _.Source(result : _ option) : _ option = result


let option = OptionBuilder()
Expand Down Expand Up @@ -97,7 +97,7 @@ module OptionExtensions =
// /// <summary>
// /// Method lets us transform data types into our internal representation.
// /// </summary>
member inline _.Source(nullable : Nullable<'a>) : Option<'a> = nullable |> Option.ofNullable
member inline _.Source(nullable : Nullable<'a>) : 'a option = nullable |> Option.ofNullable



2 changes: 1 addition & 1 deletion tests/FsToolkit.ErrorHandling.Tests/OptionCE.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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" [
Expand Down

0 comments on commit bf89b42

Please sign in to comment.