Skip to content

Commit af9f42d

Browse files
committed
Ran fantomas
1 parent cbf124b commit af9f42d

22 files changed

+785
-780
lines changed

benchmarks/Benchmarks.fs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -304,10 +304,8 @@ type ResultBuilder() =
304304
member this.Zero() : Result<unit, 'TError> = this.Return()
305305

306306
member _.Bind
307-
(
308-
result: Result<'T, 'TError>,
309-
binder: 'T -> Result<'U, 'TError>
310-
) : Result<'U, 'TError> =
307+
(result: Result<'T, 'TError>, binder: 'T -> Result<'U, 'TError>)
308+
: Result<'U, 'TError> =
311309
Result.bind binder result
312310

313311

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

321319
member inline _.Bind
322-
(
323-
result: Result<'T, 'TError>,
324-
binder: 'T -> Result<'U, 'TError>
325-
) : Result<'U, 'TError> =
320+
(result: Result<'T, 'TError>, binder: 'T -> Result<'U, 'TError>)
321+
: Result<'U, 'TError> =
326322
Result.Inlined.bind binder result
327323

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

333329
member inline _.Bind
334-
(
335-
result: Result<'T, 'TError>,
336-
[<InlineIfLambda>] binder: 'T -> Result<'U, 'TError>
337-
) : Result<'U, 'TError> =
330+
(result: Result<'T, 'TError>, [<InlineIfLambda>] binder: 'T -> Result<'U, 'TError>)
331+
: Result<'U, 'TError> =
338332
Result.Alt.InlinedLambda.bind binder result
339333

340334

playground.fsx

Lines changed: 54 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ let inline id x = x
55
open FsToolkit.ErrorHandling
66

77
Result.ofChoice
8+
89
module Operators =
910

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

169170

170-
171171
module DisposableOptionThings =
172172
open System
173173
open System.Threading.Tasks
@@ -177,16 +177,23 @@ module DisposableOptionThings =
177177
[<CompilationRepresentation(CompilationRepresentationFlags.UseNullAsTrueValue)>]
178178
[<StructuralEquality; StructuralComparison>]
179179
type DisposableOption<'a when 'a :> IDisposable> =
180-
| None
181-
| Some of 'a
180+
| None
181+
| Some of 'a
182+
182183
interface IDisposable with
183184
member this.Dispose() =
184185
match this with
185186
| None -> ()
186187
| Some x -> x.Dispose()
187188

188-
static member inline OfObj<'a when 'a :> IDisposable> (x: 'a) =
189-
if box x |> isNull then None else Some x
189+
static member inline OfObj<'a when 'a :> IDisposable>(x: 'a) =
190+
if
191+
box x
192+
|> isNull
193+
then
194+
None
195+
else
196+
Some x
190197

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

201-
static member inline OfOption (x: 'a Option) =
208+
static member inline OfOption(x: 'a Option) =
202209
match x with
203210
| Option.None -> None
204211
| Option.Some x -> Some x
205212

206-
static member inline OfValueOption (x: 'a ValueOption) =
213+
static member inline OfValueOption(x: 'a ValueOption) =
207214
match x with
208215
| ValueNone -> None
209216
| ValueSome x -> Some x
210217

211-
static member inline op_Implicit (x: 'a) =
212-
DisposableOption.OfObj x
218+
static member inline op_Implicit(x: 'a) = DisposableOption.OfObj x
213219

214-
static member inline op_Implicit (x: 'a DisposableOption) =
215-
DisposableOption.ToOption x
220+
static member inline op_Implicit(x: 'a DisposableOption) = DisposableOption.ToOption x
216221

217-
static member inline op_Implicit (x: 'a DisposableOption) =
218-
DisposableOption.ToValueOption x
222+
static member inline op_Implicit(x: 'a DisposableOption) = DisposableOption.ToValueOption x
219223

220-
static member inline op_Implicit (x: 'a Option) =
221-
DisposableOption.OfOption x
224+
static member inline op_Implicit(x: 'a Option) = DisposableOption.OfOption x
222225

223-
static member inline op_Imp licit (x: 'a ValueOption) =
224-
DisposableOption.OfValueOption x
226+
static member inline op_Imp licit (x: 'a ValueOption) = DisposableOption.OfValueOption x
225227

226228

227229
[<RequireQualifiedAccess>]
@@ -230,10 +232,12 @@ module DisposableOptionThings =
230232
match x with
231233
| DisposableOption.Some x -> f x
232234
| DisposableOption.None -> None
235+
233236
let inline map f x =
234237
match x with
235-
| DisposableOption.Some x -> Some (f x)
238+
| DisposableOption.Some x -> Some(f x)
236239
| DisposableOption.None -> None
240+
237241
let inline iter f x =
238242
match x with
239243
| DisposableOption.Some x -> f x
@@ -242,16 +246,23 @@ module DisposableOptionThings =
242246

243247
[<RequireQualifiedAccess>]
244248
type AsyncDisposableOption<'a when 'a :> IAsyncDisposable> =
245-
| Some of 'a
246-
| None
249+
| Some of 'a
250+
| None
251+
247252
interface IAsyncDisposable with
248253
member this.DisposeAsync() =
249254
match this with
250255
| Some x -> x.DisposeAsync()
251256
| None -> ValueTask()
252257

253-
static member inline ofObj (x: 'a) =
254-
if box x |> isNull then None else Some x
258+
static member inline ofObj(x: 'a) =
259+
if
260+
box x
261+
|> isNull
262+
then
263+
None
264+
else
265+
Some x
255266

256267
member inline x.toOption() =
257268
match x with
@@ -263,43 +274,47 @@ module DisposableOptionThings =
263274
| Some x -> ValueOption.Some x
264275
| None -> ValueOption.None
265276

266-
static member inline ofOption (x: 'a Option) =
277+
static member inline ofOption(x: 'a Option) =
267278
match x with
268279
| Option.Some x -> Some x
269280
| Option.None -> None
270281

271-
static member inline ofValueOption (x: 'a ValueOption) =
282+
static member inline ofValueOption(x: 'a ValueOption) =
272283
match x with
273284
| ValueOption.ValueSome x -> Some x
274285
| ValueOption.ValueNone -> None
275286

276-
static member inline op_Implicit (x: 'a) =
277-
AsyncDisposableOption.ofObj x
287+
static member inline op_Implicit(x: 'a) = AsyncDisposableOption.ofObj x
278288

279-
static member inline op_Implicit (x: 'a AsyncDisposableOption) =
280-
x.toOption()
289+
static member inline op_Implicit(x: 'a AsyncDisposableOption) = x.toOption ()
281290

282-
static member inline op_Implicit (x: 'a AsyncDisposableOption) =
283-
x.toValueOption()
291+
static member inline op_Implicit(x: 'a AsyncDisposableOption) = x.toValueOption ()
284292

285-
static member inline op_Implicit (x: 'a Option) =
286-
AsyncDisposableOption.ofOption x
293+
static member inline op_Implicit(x: 'a Option) = AsyncDisposableOption.ofOption x
287294

288-
static member inline op_Implicit (x: 'a ValueOption) =
289-
AsyncDisposableOption.ofValueOption x
295+
static member inline op_Implicit(x: 'a ValueOption) = AsyncDisposableOption.ofValueOption x
290296

291297
module Examples =
292298
open DisposableOptionThings
293299
open System.Diagnostics
294300

295-
let inline implicitConv (x: ^T) : ^U = ((^T or ^U) : (static member op_Implicit : ^T -> ^U) (x))
301+
let inline implicitConv (x: ^T) : ^U =
302+
((^T or ^U): (static member op_Implicit: ^T -> ^U) (x))
303+
296304
let inline (!>) x = implicitConv x
297-
let inline (|!>) x f = f (!> x)
305+
let inline (|!>) x f = f (!>x)
298306

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

301309
let example () =
302-
use a = activitySource.StartActivity("lol") |> DisposableOption.OfObj
303-
a |!> Option.iter(fun a -> a.AddTag("hello", "world") |> ignore)
304-
()
310+
use a =
311+
activitySource.StartActivity("lol")
312+
|> DisposableOption.OfObj
305313

314+
a
315+
|!> Option.iter (fun a ->
316+
a.AddTag("hello", "world")
317+
|> ignore
318+
)
319+
320+
()

src/FsToolkit.ErrorHandling.AsyncSeq/Library.fs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,13 @@ module AsyncSeqCE =
4141

4242

4343
member this.For
44-
(
45-
xs: AsyncSeq<Result<'T, 'TError>>,
46-
binder: 'T -> Async<Result<unit, 'TError>>
47-
) : Async<Result<unit, 'TError>> =
44+
(xs: AsyncSeq<Result<'T, 'TError>>, binder: 'T -> Async<Result<unit, 'TError>>)
45+
: Async<Result<unit, 'TError>> =
4846
this.Using(xs.GetEnumerator(), (fun enum -> this.While(enum.MoveNext, binder)))
4947

5048
member this.For
51-
(
52-
xs: AsyncSeq<'T>,
53-
binder: 'T -> Async<Result<unit, 'TError>>
54-
) : Async<Result<unit, 'TError>> =
49+
(xs: AsyncSeq<'T>, binder: 'T -> Async<Result<unit, 'TError>>)
50+
: Async<Result<unit, 'TError>> =
5551
this.Using(
5652
xs.GetEnumerator(),
5753
fun enum ->

src/FsToolkit.ErrorHandling.IcedTasks/CancellableTaskOption.fs

Lines changed: 27 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,8 @@ type ValueTaskValueOptionBuilderBase() =
8181
/// Note that this requires that the first step has no result.
8282
/// This prevents constructs like `task { return 1; return 2; }`.
8383
member inline _.Combine
84-
(
85-
task1: TaskOptionCode<'TOverall, unit>,
86-
task2: TaskOptionCode<'TOverall, 'T>
87-
) : TaskOptionCode<'TOverall, 'T> =
84+
(task1: TaskOptionCode<'TOverall, unit>, task2: TaskOptionCode<'TOverall, 'T>)
85+
: TaskOptionCode<'TOverall, 'T> =
8886

8987
ResumableCode.Combine(
9088
task1,
@@ -95,10 +93,8 @@ type ValueTaskValueOptionBuilderBase() =
9593

9694
/// Builds a step that executes the body while the condition predicate is true.
9795
member inline _.While
98-
(
99-
[<InlineIfLambda>] condition: unit -> bool,
100-
body: TaskOptionCode<'TOverall, unit>
101-
) : TaskOptionCode<'TOverall, unit> =
96+
([<InlineIfLambda>] condition: unit -> bool, body: TaskOptionCode<'TOverall, unit>)
97+
: TaskOptionCode<'TOverall, unit> =
10298
let mutable keepGoing = true
10399

104100
ResumableCode.While(
@@ -120,19 +116,15 @@ type ValueTaskValueOptionBuilderBase() =
120116
/// Wraps a step in a try/with. This catches exceptions both in the evaluation of the function
121117
/// to retrieve the step, and in the continuation of the step (if any).
122118
member inline _.TryWith
123-
(
124-
body: TaskOptionCode<'TOverall, 'T>,
125-
catch: exn -> TaskOptionCode<'TOverall, 'T>
126-
) : TaskOptionCode<'TOverall, 'T> =
119+
(body: TaskOptionCode<'TOverall, 'T>, catch: exn -> TaskOptionCode<'TOverall, 'T>)
120+
: TaskOptionCode<'TOverall, 'T> =
127121
ResumableCode.TryWith(body, catch)
128122

129123
/// Wraps a step in a try/finally. This catches exceptions both in the evaluation of the function
130124
/// to retrieve the step, and in the continuation of the step (if any).
131125
member inline _.TryFinally
132-
(
133-
body: TaskOptionCode<'TOverall, 'T>,
134-
[<InlineIfLambda>] compensation: unit -> unit
135-
) : TaskOptionCode<'TOverall, 'T> =
126+
(body: TaskOptionCode<'TOverall, 'T>, [<InlineIfLambda>] compensation: unit -> unit)
127+
: TaskOptionCode<'TOverall, 'T> =
136128
ResumableCode.TryFinally(
137129
body,
138130
ResumableCode<_, _>(fun _sm ->
@@ -142,10 +134,8 @@ type ValueTaskValueOptionBuilderBase() =
142134
)
143135

144136
member inline this.For
145-
(
146-
sequence: seq<'T>,
147-
body: 'T -> TaskOptionCode<'TOverall, unit>
148-
) : TaskOptionCode<'TOverall, unit> =
137+
(sequence: seq<'T>, body: 'T -> TaskOptionCode<'TOverall, unit>)
138+
: TaskOptionCode<'TOverall, unit> =
149139
ResumableCode.Using(
150140
sequence.GetEnumerator(),
151141
// ... and its body is a while loop that advances the enumerator and runs the body on each element.
@@ -158,10 +148,8 @@ type ValueTaskValueOptionBuilderBase() =
158148
)
159149

160150
member inline internal this.TryFinallyAsync
161-
(
162-
body: TaskOptionCode<'TOverall, 'T>,
163-
compensation: unit -> ValueTask
164-
) : TaskOptionCode<'TOverall, 'T> =
151+
(body: TaskOptionCode<'TOverall, 'T>, compensation: unit -> ValueTask)
152+
: TaskOptionCode<'TOverall, 'T> =
165153
ResumableCode.TryFinallyAsync(
166154
body,
167155
ResumableCode<_, _>(fun sm ->
@@ -203,10 +191,8 @@ type ValueTaskValueOptionBuilderBase() =
203191
)
204192

205193
member inline this.Using<'Resource, 'TOverall, 'T when 'Resource :> IAsyncDisposable>
206-
(
207-
resource: 'Resource,
208-
body: 'Resource -> TaskOptionCode<'TOverall, 'T>
209-
) : TaskOptionCode<'TOverall, 'T> =
194+
(resource: 'Resource, body: 'Resource -> TaskOptionCode<'TOverall, 'T>)
195+
: TaskOptionCode<'TOverall, 'T> =
210196
this.TryFinallyAsync(
211197
(fun sm -> (body resource).Invoke(&sm)),
212198
(fun () ->
@@ -469,10 +455,8 @@ module TaskOptionCEExtensionsLowPriority =
469455
and ^Awaiter :> ICriticalNotifyCompletion
470456
and ^Awaiter: (member get_IsCompleted: unit -> bool)
471457
and ^Awaiter: (member GetResult: unit -> 'TResult1 option)>
472-
(
473-
task: ^TaskLike,
474-
continuation: ('TResult1 -> TaskOptionCode<'TOverall, 'TResult2>)
475-
) : TaskOptionCode<'TOverall, 'TResult2> =
458+
(task: ^TaskLike, continuation: ('TResult1 -> TaskOptionCode<'TOverall, 'TResult2>))
459+
: TaskOptionCode<'TOverall, 'TResult2> =
476460

477461
TaskOptionCode<'TOverall, _>(fun sm ->
478462
if __useResumableCode then
@@ -501,7 +485,13 @@ module TaskOptionCEExtensionsLowPriority =
501485
sm.Data.MethodBuilder.AwaitUnsafeOnCompleted(&awaiter, &sm)
502486
false
503487
else
504-
ValueTaskValueOptionBuilderBase.BindDynamic< ^TaskLike, 'TResult1, 'TResult2, ^Awaiter, 'TOverall>(
488+
ValueTaskValueOptionBuilderBase.BindDynamic<
489+
^TaskLike,
490+
'TResult1,
491+
'TResult2,
492+
^Awaiter,
493+
'TOverall
494+
>(
505495
&sm,
506496
task,
507497
continuation
@@ -535,10 +525,8 @@ module TaskOptionCEExtensionsLowPriority =
535525
}
536526

537527
member inline _.Using<'Resource, 'TOverall, 'T when 'Resource :> IDisposable>
538-
(
539-
resource: 'Resource,
540-
body: 'Resource -> TaskOptionCode<'TOverall, 'T>
541-
) =
528+
(resource: 'Resource, body: 'Resource -> TaskOptionCode<'TOverall, 'T>)
529+
=
542530
ResumableCode.Using(resource, body)
543531

544532
[<AutoOpen>]
@@ -612,10 +600,8 @@ module TaskOptionCEExtensionsHighPriority =
612600
)
613601

614602
member inline this.BindReturn
615-
(
616-
x: CancellableValueTaskValueOption<'T>,
617-
[<InlineIfLambda>] f
618-
) =
603+
(x: CancellableValueTaskValueOption<'T>, [<InlineIfLambda>] f)
604+
=
619605
this.Bind(x, (fun x -> this.Return(f x)))
620606

621607
// member inline _.MergeSources(t1: CancellableTaskOption<'T>, t2: CancellableTaskOption<'T1>) = TaskOption.zip t1 t2

0 commit comments

Comments
 (0)