Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions gitbook/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,15 +190,6 @@
* [Other Functions](taskValueOption/others.md)
* [zip](taskValueOption/zip.md)

* ValueTaskValueOption
* [apply](valueTaskValueOption/apply.md)
* [bind](valueTaskValueOption/bind.md)
* [Computation Expression](valueTaskValueOption/ce.md)
* [either](valueTaskValueOption/either.md)
* [map](valueTaskValueOption/map.md)
* [Other Functions](valueTaskValueOption/others.md)
* [zip](valueTaskValueOption/zip.md)

* TaskResult
* [apply](taskResult/apply.md)
* [bind](taskResult/bind.md)
Expand Down Expand Up @@ -349,6 +340,15 @@
* [Other Functions](cancellableValueTaskOption/others.md)
* [zip](cancellableValueTaskOption/zip.md)

* ValueTaskValueOption
* [apply](valueTaskValueOption/apply.md)
* [bind](valueTaskValueOption/bind.md)
* [Computation Expression](valueTaskValueOption/ce.md)
* [either](valueTaskValueOption/either.md)
* [map](valueTaskValueOption/map.md)
* [Other Functions](valueTaskValueOption/others.md)
* [zip](valueTaskValueOption/zip.md)

* [CancellableValueTaskResult](cancellableValueTaskResult/index.md)
* [apply](cancellableValueTaskResult/apply.md)
* [bind](cancellableValueTaskResult/bind.md)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
<Compile Include="CancellableTaskValidationOp.fs" />
<Compile Include="CancellableTaskOptionBuilderBase.fs" />
<Compile Include="CancellableTaskOptionCE.fs" />
<Compile Include="ValueTaskValueOption.fs" />
<Compile Include="ValueTaskValueOptionCE.fs" />
<Compile Include="ValueTaskValueOptionOp.fs" />
<Compile Include="CancellableValueTaskResultCE.fs" />
<Compile Include="CancellableValueTaskOptionCE.fs" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,46 +1,38 @@
namespace FsToolkit.ErrorHandling

open System.Threading.Tasks
open IcedTasks


[<RequireQualifiedAccess>]
module ValueTaskValueOption =

let inline map ([<InlineIfLambda>] f) (ar: ValueTask<_ voption>) =
ValueTask<_ voption>(
task {
let! opt = ar
return ValueOption.map f opt
}
)
valueTask {
let! opt = ar
return ValueOption.map f opt
}

let inline bind ([<InlineIfLambda>] f) (ar: ValueTask<_ voption>) =
ValueTask<_ voption>(
task {
let! opt = ar
valueTask {
let! opt = ar

let t =
match opt with
| ValueSome x -> f x
| ValueNone -> ValueTask<_ voption>(ValueNone)

return! t
}
)
match opt with
| ValueSome x -> return! f x
| ValueNone -> return ValueNone
}

let inline valueSome x = ValueTask<_ voption>(ValueSome x)

let inline apply f x =
bind (fun f' -> bind (fun x' -> valueSome (f' x')) x) f

let inline zip (x1: ValueTask<'a voption>) (x2: ValueTask<'b voption>) =
ValueTask<('a * 'b) voption>(
task {
let! r1 = x1
let! r2 = x2
return ValueOption.zip r1 r2
}
)
valueTask {
let! r1 = x1
let! r2 = x2
return ValueOption.zip r1 r2
}

/// <summary>
/// Returns result of running <paramref name="onValueSome"/> if it is <c>ValueSome</c>, otherwise returns result of running <paramref name="onValueNone"/>
Expand All @@ -56,15 +48,13 @@ module ValueTaskValueOption =
([<InlineIfLambda>] onValueNone: unit -> ValueTask<'output>)
(input: ValueTask<'input voption>)
: ValueTask<'output> =
ValueTask<'output>(
task {
let! opt = input
valueTask {
let! opt = input

match opt with
| ValueSome v -> return! onValueSome v
| ValueNone -> return! onValueNone ()
}
)
match opt with
| ValueSome v -> return! onValueSome v
| ValueNone -> return! onValueNone ()
}

/// <summary>
/// Gets the value of the voption if the voption is <c>ValueSome</c>, otherwise returns the specified default value.
Expand All @@ -75,12 +65,10 @@ module ValueTaskValueOption =
/// The voption if the voption is <c>ValueSome</c>, else the default value.
/// </returns>
let inline defaultValue (value: 'value) (valueTaskValueOption: ValueTask<'value voption>) =
ValueTask<'value>(
task {
let! opt = valueTaskValueOption
return ValueOption.defaultValue value opt
}
)
valueTask {
let! opt = valueTaskValueOption
return ValueOption.defaultValue value opt
}

/// <summary>
/// Gets the value of the voption if the voption is <c>ValueSome</c>, otherwise evaluates <paramref name="defThunk"/> and returns the result.
Expand All @@ -94,9 +82,7 @@ module ValueTaskValueOption =
([<InlineIfLambda>] defThunk: unit -> 'value)
(valueTaskValueOption: ValueTask<'value voption>)
: ValueTask<'value> =
ValueTask<'value>(
task {
let! opt = valueTaskValueOption
return ValueOption.defaultWith defThunk opt
}
)
valueTask {
let! opt = valueTaskValueOption
return ValueOption.defaultWith defThunk opt
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ open Microsoft.FSharp.Core.CompilerServices.StateMachineHelpers
open Microsoft.FSharp.Core.LanguagePrimitives.IntrinsicOperators
open Microsoft.FSharp.Control
open Microsoft.FSharp.Collections
open IcedTasks

/// ValueTask<'T voption>
type ValueTaskValueOption<'T> = ValueTask<'T voption>
Expand Down Expand Up @@ -431,12 +432,10 @@ module ValueTaskValueOptionCEExtensionsLowPriority =
(t: ^TaskLike)
: ValueTaskValueOption<'T> =

ValueTask<'T voption>(
task {
let! r = t
return ValueSome r
}
)
valueTask {
let! r = t
return ValueSome r
}

member inline _.Using<'Resource, 'TOverall, 'T when 'Resource :> IDisposableNull>
(resource: 'Resource, body: 'Resource -> ValueTaskValueOptionCode<'TOverall, 'T>)
Expand Down Expand Up @@ -533,31 +532,28 @@ module ValueTaskValueOptionCEExtensionsMediumPriority =
type ValueTaskValueOptionBuilderBase with

member inline this.Source(t: Task<'T>) : ValueTaskValueOption<'T> =
ValueTask<'T voption>(Task.map ValueSome t)
valueTask {
let! r = t
return ValueSome r
}

member inline this.Source(t: Task) : ValueTaskValueOption<unit> =
ValueTask<unit voption>(
task {
do! t
return ValueSome()
}
)
valueTask {
do! t
return ValueSome()
}

member inline this.Source(t: ValueTask<'T>) : ValueTaskValueOption<'T> =
ValueTask<'T voption>(
task {
let! r = t
return ValueSome r
}
)
valueTask {
let! r = t
return ValueSome r
}

member inline this.Source(t: ValueTask) : ValueTaskValueOption<unit> =
ValueTask<unit voption>(
task {
do! t
return ValueSome()
}
)
valueTask {
do! t
return ValueSome()
}

member inline this.Source(opt: 'T voption) : ValueTaskValueOption<'T> =
ValueTask<'T voption>(opt)
Expand Down
5 changes: 1 addition & 4 deletions src/FsToolkit.ErrorHandling/FsToolkit.ErrorHandling.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,10 @@
<Compile Include="AsyncOptionOp.fs" />
<Compile Include="TaskOption.fs" Condition="'$(FABLE_COMPILER)' != 'true'" />
<Compile Include="TaskValueOption.fs" Condition="'$(FABLE_COMPILER)' != 'true'" />
<Compile Include="ValueTaskValueOption.fs" Condition="'$(FABLE_COMPILER)' != 'true'" />
<Compile Include="TaskOptionCE.fs" Condition="'$(FABLE_COMPILER)' != 'true'" />
<Compile Include="TaskValueOptionCE.fs" Condition="'$(FABLE_COMPILER)' != 'true'" />
<Compile Include="ValueTaskValueOptionCE.fs" Condition="'$(FABLE_COMPILER)' != 'true'" />
<Compile Include="TaskOptionOp.fs" Condition="'$(FABLE_COMPILER)' != 'true'" />
<Compile Include="TaskValueOptionOp.fs" Condition="'$(FABLE_COMPILER)' != 'true'" />
<Compile Include="ValueTaskValueOptionOp.fs" Condition="'$(FABLE_COMPILER)' != 'true'" />
<Compile Include="AsyncResultOption.fs" />
<Compile Include="AsyncResultOptionCE.fs" />
<Compile Include="AsyncResultOptionOp.fs" />
Expand All @@ -66,4 +63,4 @@
<ItemGroup>
<Content Include="*.fsproj; **\*.fs" Exclude="Task.fs; **\Task*.fs" PackagePath="fable\" />
</ItemGroup>
</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
<Compile Include="TestData.fs" />
<Compile Include="Expect.fs" />
<Compile Include="../FsToolkit.ErrorHandling.Tests/Expecto.fs" />
<Compile Include="../FsToolkit.ErrorHandling.Tests/TestHelpers.fs" />
<Compile Include="CancellableTaskResultCE.fs" />
<Compile Include="CancellableTaskValidationCE.fs" />
<Compile Include="CancellableTaskOptionCE.fs" />
<Compile Include="ValueTaskValueOptionCE.fs" />
<Compile Include="CancellableValueTaskResultCE.fs" />
<Compile Include="CancellableValueTaskOptionCE.fs" />
<Compile Include="Main.fs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module ValueTaskValueOptionCETests
module FsToolkit.ErrorHandling.IcedTasks.Tests.ValueTaskValueOptionCETests

open Expecto
open FsToolkit.ErrorHandling
Expand Down Expand Up @@ -604,6 +604,7 @@ let ``ValueTaskValueOptionCE inference checks`` =
|> ignore
]

[<Tests>]
let allTests =
testList "ValueTaskValueOption CE Tests" [
ceTests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
<Compile Include="TaskValueOption.fs" Condition="'$(FABLE_COMPILER)' != 'true'" />
<Compile Include="TaskOptionCE.fs" Condition="'$(FABLE_COMPILER)' != 'true'" />
<Compile Include="TaskValueOptionCE.fs" Condition="'$(FABLE_COMPILER)' != 'true'" />
<Compile Include="ValueTaskValueOptionCE.fs" Condition="'$(FABLE_COMPILER)' != 'true'" />
<Compile Include="TaskResult.fs" Condition="'$(FABLE_COMPILER)' != 'true'" />
<Compile Include="TaskResultCE.fs" Condition="'$(FABLE_COMPILER)' != 'true'" />
<Compile Include="TaskResultOption.fs" Condition="'$(FABLE_COMPILER)' != 'true'" />
Expand Down
1 change: 0 additions & 1 deletion tests/FsToolkit.ErrorHandling.Tests/Main.fs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ let allTests =
TaskOptionCETests.allTests
TaskValueOptionTests.allTests
TaskValueOptionCETests.allTests
ValueTaskValueOptionCETests.allTests
TaskResultTests.allTests
TaskResultCETests.allTests
TaskResultOptionTests.allTests
Expand Down
Loading