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
58 changes: 31 additions & 27 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,34 @@
{
"version": 1,
"isRoot": true,
"tools": {
"paket": {
"version": "8.0.3",
"commands": [
"paket"
]
},
"fable": {
"version": "4.4.0",
"commands": [
"fable"
]
},
"fantomas": {
"version": "6.0.0-alpha-010",
"commands": [
"fantomas"
]
},
"femto": {
"version": "0.19.0",
"commands": [
"femto"
]
}
"version": 1,
"isRoot": true,
"tools": {
"paket": {
"version": "8.0.3",
"commands": [
"paket"
],
"rollForward": false
},
"fable": {
"version": "4.4.0",
"commands": [
"fable"
],
"rollForward": false
},
"fantomas": {
"version": "6.3.16",
"commands": [
"fantomas"
],
"rollForward": false
},
"femto": {
"version": "0.19.0",
"commands": [
"femto"
],
"rollForward": false
}
}
}
2 changes: 2 additions & 0 deletions .fantomasignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
AssemblyInfo.fs
tests/FsToolkit.ErrorHandling.AsyncSeq.Tests/Main.fs
tests/FsToolkit.ErrorHandling.Tests/Main.fs
18 changes: 6 additions & 12 deletions benchmarks/Benchmarks.fs
Original file line number Diff line number Diff line change
Expand Up @@ -304,10 +304,8 @@ type ResultBuilder() =
member this.Zero() : Result<unit, 'TError> = this.Return()

member _.Bind
(
result: Result<'T, 'TError>,
binder: 'T -> Result<'U, 'TError>
) : Result<'U, 'TError> =
(result: Result<'T, 'TError>, binder: 'T -> Result<'U, 'TError>)
: Result<'U, 'TError> =
Result.bind binder result


Expand All @@ -319,10 +317,8 @@ type ResultBuilderInlined() =
member inline this.Zero() : Result<unit, 'TError> = this.Return()

member inline _.Bind
(
result: Result<'T, 'TError>,
binder: 'T -> Result<'U, 'TError>
) : Result<'U, 'TError> =
(result: Result<'T, 'TError>, binder: 'T -> Result<'U, 'TError>)
: Result<'U, 'TError> =
Result.Inlined.bind binder result

type ResultBuilderInlinedLambda() =
Expand All @@ -331,10 +327,8 @@ type ResultBuilderInlinedLambda() =
member inline this.Zero() : Result<unit, 'TError> = this.Return()

member inline _.Bind
(
result: Result<'T, 'TError>,
[<InlineIfLambda>] binder: 'T -> Result<'U, 'TError>
) : Result<'U, 'TError> =
(result: Result<'T, 'TError>, [<InlineIfLambda>] binder: 'T -> Result<'U, 'TError>)
: Result<'U, 'TError> =
Result.Alt.InlinedLambda.bind binder result


Expand Down
4 changes: 3 additions & 1 deletion build/build.fs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,9 @@ let checkFormatCode _ =
elif result.ExitCode = 99 then
failwith "Some files need formatting, check output for more info"
else
Trace.logf "Errors while formatting: %A" result.Errors
let msg = sprintf "Errors while formatting: %A" result.Errors
Trace.log msg
failwith msg


let clean _ =
Expand Down
93 changes: 54 additions & 39 deletions playground.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ let inline id x = x
open FsToolkit.ErrorHandling

Result.ofChoice

module Operators =

let inline bindM builder m ([<InlineIfLambda>] f) =
Expand Down Expand Up @@ -167,7 +168,6 @@ module AsyncResult =
}



module DisposableOptionThings =
open System
open System.Threading.Tasks
Expand All @@ -177,16 +177,23 @@ module DisposableOptionThings =
[<CompilationRepresentation(CompilationRepresentationFlags.UseNullAsTrueValue)>]
[<StructuralEquality; StructuralComparison>]
type DisposableOption<'a when 'a :> IDisposable> =
| None
| Some of 'a
| None
| Some of 'a

interface IDisposable with
member this.Dispose() =
match this with
| None -> ()
| Some x -> x.Dispose()

static member inline OfObj<'a when 'a :> IDisposable> (x: 'a) =
if box x |> isNull then None else Some x
static member inline OfObj<'a when 'a :> IDisposable>(x: 'a) =
if
box x
|> isNull
then
None
else
Some x

static member inline ToOption(x: DisposableOption<'a>) =
match x with
Expand All @@ -198,30 +205,25 @@ module DisposableOptionThings =
| None -> ValueOption.None
| Some x -> ValueOption.Some x

static member inline OfOption (x: 'a Option) =
static member inline OfOption(x: 'a Option) =
match x with
| Option.None -> None
| Option.Some x -> Some x

static member inline OfValueOption (x: 'a ValueOption) =
static member inline OfValueOption(x: 'a ValueOption) =
match x with
| ValueNone -> None
| ValueSome x -> Some x

static member inline op_Implicit (x: 'a) =
DisposableOption.OfObj x
static member inline op_Implicit(x: 'a) = DisposableOption.OfObj x

static member inline op_Implicit (x: 'a DisposableOption) =
DisposableOption.ToOption x
static member inline op_Implicit(x: 'a DisposableOption) = DisposableOption.ToOption x

static member inline op_Implicit (x: 'a DisposableOption) =
DisposableOption.ToValueOption x
static member inline op_Implicit(x: 'a DisposableOption) = DisposableOption.ToValueOption x

static member inline op_Implicit (x: 'a Option) =
DisposableOption.OfOption x
static member inline op_Implicit(x: 'a Option) = DisposableOption.OfOption x

static member inline op_Imp licit (x: 'a ValueOption) =
DisposableOption.OfValueOption x
static member inline op_Imp licit (x: 'a ValueOption) = DisposableOption.OfValueOption x


[<RequireQualifiedAccess>]
Expand All @@ -230,10 +232,12 @@ module DisposableOptionThings =
match x with
| DisposableOption.Some x -> f x
| DisposableOption.None -> None

let inline map f x =
match x with
| DisposableOption.Some x -> Some (f x)
| DisposableOption.Some x -> Some(f x)
| DisposableOption.None -> None

let inline iter f x =
match x with
| DisposableOption.Some x -> f x
Expand All @@ -242,16 +246,23 @@ module DisposableOptionThings =

[<RequireQualifiedAccess>]
type AsyncDisposableOption<'a when 'a :> IAsyncDisposable> =
| Some of 'a
| None
| Some of 'a
| None

interface IAsyncDisposable with
member this.DisposeAsync() =
match this with
| Some x -> x.DisposeAsync()
| None -> ValueTask()

static member inline ofObj (x: 'a) =
if box x |> isNull then None else Some x
static member inline ofObj(x: 'a) =
if
box x
|> isNull
then
None
else
Some x

member inline x.toOption() =
match x with
Expand All @@ -263,43 +274,47 @@ module DisposableOptionThings =
| Some x -> ValueOption.Some x
| None -> ValueOption.None

static member inline ofOption (x: 'a Option) =
static member inline ofOption(x: 'a Option) =
match x with
| Option.Some x -> Some x
| Option.None -> None

static member inline ofValueOption (x: 'a ValueOption) =
static member inline ofValueOption(x: 'a ValueOption) =
match x with
| ValueOption.ValueSome x -> Some x
| ValueOption.ValueNone -> None

static member inline op_Implicit (x: 'a) =
AsyncDisposableOption.ofObj x
static member inline op_Implicit(x: 'a) = AsyncDisposableOption.ofObj x

static member inline op_Implicit (x: 'a AsyncDisposableOption) =
x.toOption()
static member inline op_Implicit(x: 'a AsyncDisposableOption) = x.toOption ()

static member inline op_Implicit (x: 'a AsyncDisposableOption) =
x.toValueOption()
static member inline op_Implicit(x: 'a AsyncDisposableOption) = x.toValueOption ()

static member inline op_Implicit (x: 'a Option) =
AsyncDisposableOption.ofOption x
static member inline op_Implicit(x: 'a Option) = AsyncDisposableOption.ofOption x

static member inline op_Implicit (x: 'a ValueOption) =
AsyncDisposableOption.ofValueOption x
static member inline op_Implicit(x: 'a ValueOption) = AsyncDisposableOption.ofValueOption x

module Examples =
open DisposableOptionThings
open System.Diagnostics

let inline implicitConv (x: ^T) : ^U = ((^T or ^U) : (static member op_Implicit : ^T -> ^U) (x))
let inline implicitConv (x: ^T) : ^U =
((^T or ^U): (static member op_Implicit: ^T -> ^U) (x))

let inline (!>) x = implicitConv x
let inline (|!>) x f = f (!> x)
let inline (|!>) x f = f (!>x)

let activitySource = new ActivitySource("Playground.App")

let example () =
use a = activitySource.StartActivity("lol") |> DisposableOption.OfObj
a |!> Option.iter(fun a -> a.AddTag("hello", "world") |> ignore)
()
use a =
activitySource.StartActivity("lol")
|> DisposableOption.OfObj

a
|!> Option.iter (fun a ->
a.AddTag("hello", "world")
|> ignore
)

()
12 changes: 4 additions & 8 deletions src/FsToolkit.ErrorHandling.AsyncSeq/Library.fs
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,13 @@ module AsyncSeqCE =


member this.For
(
xs: AsyncSeq<Result<'T, 'TError>>,
binder: 'T -> Async<Result<unit, 'TError>>
) : Async<Result<unit, 'TError>> =
(xs: AsyncSeq<Result<'T, 'TError>>, binder: 'T -> Async<Result<unit, 'TError>>)
: Async<Result<unit, 'TError>> =
this.Using(xs.GetEnumerator(), (fun enum -> this.While(enum.MoveNext, binder)))

member this.For
(
xs: AsyncSeq<'T>,
binder: 'T -> Async<Result<unit, 'TError>>
) : Async<Result<unit, 'TError>> =
(xs: AsyncSeq<'T>, binder: 'T -> Async<Result<unit, 'TError>>)
: Async<Result<unit, 'TError>> =
this.Using(
xs.GetEnumerator(),
fun enum ->
Expand Down
Loading
Loading