Skip to content

Commit

Permalink
205 overload resolution (#252)
Browse files Browse the repository at this point in the history
* Missed this in net8 additions

* Fix overload resolution issues in Core

* Fix overload resolution issues in Tasks/Hopac

* Fix overload resolution issues in CancellableTaskResult

* WIP: TaskValidtionCE

* Wip merge sources

* Fix MergeSources for CTValidation

* cleanup

* Ensure IAsyncDisposable tests

* ignore nuget stuff
  • Loading branch information
TheAngryByrd committed Apr 6, 2024
1 parent ab64ba3 commit 08cf82b
Show file tree
Hide file tree
Showing 38 changed files with 3,402 additions and 1,743 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:
pull_request:
branches:
- master
workflow_dispatch:

jobs:

Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>
<PropertyGroup>
<DisableCheckingDuplicateNuGetItems>true</DisableCheckingDuplicateNuGetItems>
<NoWarn>$(NoWarn);FS2003; NU1903</NoWarn>
<NoWarn>$(NoWarn);FS2003; NU1903; NU1904</NoWarn>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<WarningsAsErrors />
</PropertyGroup>
Expand Down
1,365 changes: 1,365 additions & 0 deletions src/FsToolkit.ErrorHandling.IcedTasks/CancellableTaskResultBuilderBase.fs

Large diffs are not rendered by default.

906 changes: 260 additions & 646 deletions src/FsToolkit.ErrorHandling.IcedTasks/CancellableTaskResultCE.fs

Large diffs are not rendered by default.

1,774 changes: 909 additions & 865 deletions src/FsToolkit.ErrorHandling.IcedTasks/CancellableTaskValidationCE.fs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFrameworks>netstandard2.0;netstandard2.1</TargetFrameworks>
<TargetFrameworks>net6.0;netstandard2.0;netstandard2.1</TargetFrameworks>
<LangVersion>preview</LangVersion>
<DebugType>portable</DebugType>
<NoWarn>FS3511;FS3513</NoWarn>
</PropertyGroup>
<ItemGroup>
<Compile Include="CancellableTaskResultBuilderBase.fs" />
<Compile Include="CancellableTaskResultCE.fs" />
<None Include="paket.references" />
<Compile Include="CancellableTaskValidationCE.fs" />
<Compile Include="CancellableTaskValidationOp.fs" />
<Watch Include="@(None)" />
</ItemGroup>
<ItemGroup>
<ProjectReference
Expand Down
34 changes: 21 additions & 13 deletions src/FsToolkit.ErrorHandling.JobResult/JobOptionCE.fs
Original file line number Diff line number Diff line change
Expand Up @@ -118,19 +118,6 @@ module JobOptionCE =
/// </summary>
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

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

let jobOption = JobOptionBuilder()

Expand Down Expand Up @@ -173,3 +160,24 @@ module JobOptionCEExtensions =
a
|> Job.awaitTask
|> Job.map Some

[<AutoOpen>]
// Having members as extensions gives them lower priority in
// overload resolution and allows skipping more type annotations.
module JobOptionCEExtensions2 =

type JobOptionBuilder with

/// <summary>
/// Method lets us transform data types into our internal representation.
/// </summary>
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
33 changes: 19 additions & 14 deletions src/FsToolkit.ErrorHandling.JobResult/JobResultCE.fs
Original file line number Diff line number Diff line change
Expand Up @@ -123,20 +123,6 @@ module JobResultCE =
/// </summary>
member inline _.Source(job': Job<Result<_, _>>) : Job<Result<_, _>> = job'

/// <summary>
/// Method lets us transform data types into our internal representation. This is the identity method to recognize the self type.
/// </summary>
member inline _.Source(task: Task<Result<_, _>>) : Job<Result<_, _>> =
task
|> Job.awaitTask

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

let jobResult = JobResultBuilder()

[<AutoOpen>]
Expand Down Expand Up @@ -194,3 +180,22 @@ module JobResultCEExtensions =
t
|> Job.awaitUnitTask
|> Job.map Ok


[<AutoOpen>]
module JobResultCEExtensions2 =
type JobResultBuilder with

/// <summary>
/// Method lets us transform data types into our internal representation. This is the identity method to recognize the self type.
/// </summary>
member inline _.Source(task: Task<Result<_, _>>) : Job<Result<_, _>> =
task
|> Job.awaitTask

/// <summary>
/// Method lets us transform data types into our internal representation.
/// </summary>
member inline _.Source(result: Async<Result<_, _>>) : Job<Result<_, _>> =
result
|> Job.fromAsync
22 changes: 14 additions & 8 deletions src/FsToolkit.ErrorHandling.TaskResult/TaskOptionCE.fs
Original file line number Diff line number Diff line change
Expand Up @@ -212,16 +212,8 @@ type TaskOptionBuilderBase() =
)
)

member inline this.Source(computation: Async<'T option>) : TaskOption<'T> =
computation
|> Async.StartImmediateAsTask

member inline this.Source(taskOption: TaskOption<'T>) : TaskOption<'T> = taskOption

member inline this.Source(taskOption: ValueTask<'T option>) : TaskOption<'T> =
taskOption.AsTask()


type TaskOptionBuilder() =

inherit TaskOptionBuilderBase()
Expand Down Expand Up @@ -617,3 +609,17 @@ module TaskOptionCEExtensionsMediumPriority =
computation
|> Async.map Some
|> Async.StartImmediateAsTask


[<AutoOpen>]
module TaskOptionCEExtensionsHighPriority2 =

// Medium priority extensions
type TaskOptionBuilderBase with

member inline this.Source(computation: Async<'T option>) : TaskOption<'T> =
computation
|> Async.StartImmediateAsTask

member inline this.Source(taskOption: ValueTask<'T option>) : TaskOption<'T> =
taskOption.AsTask()
33 changes: 20 additions & 13 deletions src/FsToolkit.ErrorHandling.TaskResult/TaskResultCE.fs
Original file line number Diff line number Diff line change
Expand Up @@ -218,19 +218,6 @@ type TaskResultBuilderBase() =
member inline this.Source(taskResult: TaskResult<'T, 'Error>) : TaskResult<'T, 'Error> =
taskResult

member inline _.Source(result: Async<Result<_, _>>) : Task<Result<_, _>> =
result
|> Async.StartImmediateAsTask

member inline _.Source(t: ValueTask<Result<_, _>>) : Task<Result<_, _>> = task { return! t }

member inline _.Source(result: Result<_, _>) : Task<Result<_, _>> = Task.singleton result

member inline _.Source(result: Choice<_, _>) : Task<Result<_, _>> =
result
|> Result.ofChoice
|> Task.singleton


type TaskResultBuilder() =

Expand Down Expand Up @@ -591,3 +578,23 @@ module TaskResultCEExtensionsMediumPriority =
computation
|> Async.map Ok
|> Async.StartImmediateAsTask

[<AutoOpen>]
module TaskResultCEExtensionsHighPriority2 =

// Medium priority extensions
type TaskResultBuilderBase with


member inline _.Source(result: Async<Result<_, _>>) : Task<Result<_, _>> =
result
|> Async.StartImmediateAsTask

member inline _.Source(t: ValueTask<Result<_, _>>) : Task<Result<_, _>> = task { return! t }

member inline _.Source(result: Result<_, _>) : Task<Result<_, _>> = Task.singleton result

member inline _.Source(result: Choice<_, _>) : Task<Result<_, _>> =
result
|> Result.ofChoice
|> Task.singleton
2 changes: 1 addition & 1 deletion src/FsToolkit.ErrorHandling.TaskResult/TaskResultOption.fs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module TaskResultOption =
let inline map3 ([<InlineIfLambda>] f) xTRO yTRO zTRO =
TaskResult.map3 (Option.map3 f) xTRO yTRO zTRO

let inline retn value = TaskResult.retn (Ok value)
let inline retn value = TaskResult.retn (Some value)

let inline apply fTRO xTRO = map2 (fun f x -> f x) fTRO xTRO

Expand Down
22 changes: 13 additions & 9 deletions src/FsToolkit.ErrorHandling/AsyncOptionCE.fs
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,6 @@ module AsyncOptionCE =
/// </summary>
member inline _.Source(async: Async<'value option>) : Async<'value option> = async

#if !FABLE_COMPILER
/// <summary>
/// Method lets us transform data types into our internal representation.
/// </summary>
member inline _.Source(task: Task<'value option>) : Async<'value option> =
task
|> Async.AwaitTask

#endif

let asyncOption = AsyncOptionBuilder()

Expand Down Expand Up @@ -177,4 +168,17 @@ module AsyncOptionCEExtensions =
a
|> Async.AwaitTask
|> Async.map Some

[<AutoOpen>]
module AsyncOptionCEExtensionsHigher =

type AsyncOptionBuilder with

/// <summary>
/// Method lets us transform data types into our internal representation.
/// </summary>
member inline _.Source(task: Task<'value option>) : Async<'value option> =
task
|> Async.AwaitTask

#endif
22 changes: 14 additions & 8 deletions src/FsToolkit.ErrorHandling/AsyncResultCE.fs
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,6 @@ module AsyncResultCE =
member inline _.Source(result: Async<Result<'ok, 'error>>) : Async<Result<'ok, 'error>> =
result

#if !FABLE_COMPILER
/// <summary>
/// Method lets us transform data types into our internal representation.
/// </summary>
member inline _.Source(task: Task<Result<'ok, 'error>>) : Async<Result<'ok, 'error>> =
task
|> Async.AwaitTask
#endif

let asyncResult = AsyncResultBuilder()

Expand Down Expand Up @@ -211,3 +203,17 @@ module AsyncResultCEExtensions =
|> Async.AwaitTask
|> Async.map Ok
#endif

#if !FABLE_COMPILER
[<AutoOpen>]
module AsyncResultCEExtensions2 =

type AsyncResultBuilder with

/// <summary>
/// Method lets us transform data types into our internal representation.
/// </summary>
member inline _.Source(task: Task<Result<'ok, 'error>>) : Async<Result<'ok, 'error>> =
task
|> Async.AwaitTask
#endif
31 changes: 19 additions & 12 deletions src/FsToolkit.ErrorHandling/AsyncResultOptionCE.fs
Original file line number Diff line number Diff line change
Expand Up @@ -103,19 +103,7 @@ module AsyncResultOptionCE =
(result: AsyncResultOption<'ok, 'error>)
: AsyncResultOption<'ok, 'error> =
result
#if !FABLE_COMPILER

/// <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
(result: Task<Result<Option<'ok>, 'error>>)
: AsyncResultOption<'ok, 'error> =
result
|> Async.AwaitTask
#endif
let asyncResultOption = new AsyncResultOptionBuilder()


Expand Down Expand Up @@ -231,3 +219,22 @@ module AsyncResultOptionCEExtensionsHighPriority =
|> Async.AwaitTask
|> AsyncResultOption.ofAsyncOption
#endif

#if !FABLE_COMPILER
[<AutoOpen>]
module AsyncResultOptionCEExtensionsHighPriority2 =

type AsyncResultOptionBuilder with


/// <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
(result: Task<Result<Option<'ok>, 'error>>)
: AsyncResultOption<'ok, 'error> =
result
|> Async.AwaitTask
#endif
16 changes: 8 additions & 8 deletions src/FsToolkit.ErrorHandling/OptionCE.fs
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,6 @@ module OptionCE =
member inline _.Source(result: 'value option) : 'value option = result


/// <summary>
/// Method lets us transform data types into our internal representation.
/// </summary>
member inline _.Source(vopt: 'value voption) : 'value option = Option.ofValueOption vopt

let option = OptionBuilder()

[<AutoOpen>]
Expand Down Expand Up @@ -176,8 +171,13 @@ module OptionExtensions =
/// </summary>
member inline _.Source(s: #seq<'value>) : #seq<'value> = s

// /// <summary>
// /// Method lets us transform data types into our internal representation.
// /// </summary>
/// <summary>
/// Method lets us transform data types into our internal representation.
/// </summary>
member inline _.Source(nullable: Nullable<'value>) : 'value option =
Option.ofNullable nullable

/// <summary>
/// Method lets us transform data types into our internal representation.
/// </summary>
member inline _.Source(vopt: 'value voption) : 'value option = Option.ofValueOption vopt
21 changes: 11 additions & 10 deletions src/FsToolkit.ErrorHandling/ValueOptionCE.fs
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,6 @@ module ValueOptionCE =
member inline _.Source(result: _ voption) : _ voption = result


// /// <summary>
// /// Method lets us transform data types into our internal representation.
// /// </summary>
member inline _.Source(vopt: _ option) : _ voption =
vopt
|> ValueOption.ofOption

let voption = ValueOptionBuilder()

[<AutoOpen>]
Expand Down Expand Up @@ -156,10 +149,18 @@ module ValueOptionExtensions =
/// </summary>
member inline _.Source(s: #seq<_>) = s

// /// <summary>
// /// Method lets us transform data types into our internal representation.
// /// </summary>
/// <summary>
/// Method lets us transform data types into our internal representation.
/// </summary>
member inline _.Source(nullable: Nullable<'a>) : 'a voption =
nullable
|> ValueOption.ofNullable


/// <summary>
/// Method lets us transform data types into our internal representation.
/// </summary>
member inline _.Source(vopt: _ option) : _ voption =
vopt
|> ValueOption.ofOption
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<LangVersion>preview</LangVersion>
</PropertyGroup>
<ItemGroup>
Expand Down
Loading

0 comments on commit 08cf82b

Please sign in to comment.