Skip to content

Commit 7d55011

Browse files
committed
Formatting
1 parent 3e1e772 commit 7d55011

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+3039
-896
lines changed

src/FsToolkit.ErrorHandling.AsyncSeq/Library.fs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ module AsyncSeqCE =
2929
| Some (Ok x) -> return! whileAsync x
3030
| Some (Error e) -> return Error e
3131
| None -> return! this.Zero()
32-
})
32+
}
33+
)
3334
)
3435

3536
return! whileAsync x
@@ -45,11 +46,17 @@ module AsyncSeqCE =
4546
) : Async<Result<unit, 'TError>> =
4647
this.Using(xs.GetEnumerator(), (fun enum -> this.While(enum.MoveNext, binder)))
4748

48-
member this.For(xs: AsyncSeq<'T>, binder: 'T -> Async<Result<unit, 'TError>>) : Async<Result<unit, 'TError>> =
49+
member this.For
50+
(
51+
xs: AsyncSeq<'T>,
52+
binder: 'T -> Async<Result<unit, 'TError>>
53+
) : Async<Result<unit, 'TError>> =
4954
this.Using(
5055
xs.GetEnumerator(),
5156
fun enum ->
52-
let moveNext = enum.MoveNext >> Async.map (Option.map Ok)
57+
let moveNext =
58+
enum.MoveNext
59+
>> Async.map (Option.map Ok)
5360

5461
this.While(moveNext, binder)
5562
)

src/FsToolkit.ErrorHandling.IcedTasks/CancellableTaskResultCE.fs

Lines changed: 151 additions & 58 deletions
Large diffs are not rendered by default.

src/FsToolkit.ErrorHandling.JobResult/JobOptionCE.fs

Lines changed: 50 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,28 @@ module JobOptionCE =
99

1010
type JobOptionBuilder() =
1111

12-
member inline _.Return(value: 'T) : Job<_ option> = job.Return <| option.Return value
12+
member inline _.Return(value: 'T) : Job<_ option> =
13+
job.Return
14+
<| option.Return value
1315

1416
member inline _.ReturnFrom(jobResult: Job<_ option>) : Job<_ option> = jobResult
1517

16-
member inline _.Zero() : Job<_ option> = job.Return <| option.Zero()
18+
member inline _.Zero() : Job<_ option> =
19+
job.Return
20+
<| option.Zero()
1721

18-
member inline _.Bind(jobResult: Job<_ option>, [<InlineIfLambda>] binder: 'T -> Job<_ option>) : Job<_ option> = job {
19-
let! result = jobResult
22+
member inline _.Bind
23+
(
24+
jobResult: Job<_ option>,
25+
[<InlineIfLambda>] binder: 'T -> Job<_ option>
26+
) : Job<_ option> =
27+
job {
28+
let! result = jobResult
2029

21-
match result with
22-
| Some x -> return! binder x
23-
| None -> return None
24-
}
30+
match result with
31+
| Some x -> return! binder x
32+
| None -> return None
33+
}
2534

2635
member inline this.Bind
2736
(
@@ -30,9 +39,14 @@ module JobOptionCE =
3039
) : Job<_ option> =
3140
this.Bind(Job.fromTask taskResult, binder)
3241

33-
member inline _.Delay([<InlineIfLambda>] generator: unit -> Job<_ option>) : Job<_ option> = Job.delay generator
42+
member inline _.Delay([<InlineIfLambda>] generator: unit -> Job<_ option>) : Job<_ option> =
43+
Job.delay generator
3444

35-
member inline this.Combine(computation1: Job<_ option>, computation2: Job<_ option>) : Job<_ option> =
45+
member inline this.Combine
46+
(
47+
computation1: Job<_ option>,
48+
computation2: Job<_ option>
49+
) : Job<_ option> =
3650
this.Bind(computation1, (fun () -> computation2))
3751

3852
member inline _.TryWith
@@ -71,12 +85,19 @@ module JobOptionCE =
7185
job.Using(resource, binder)
7286

7387
member this.While(guard: unit -> bool, computation: Job<_ option>) : Job<_ option> =
74-
if not <| guard () then
88+
if
89+
not
90+
<| guard ()
91+
then
7592
this.Zero()
7693
else
7794
this.Bind(computation, (fun () -> this.While(guard, computation)))
7895

79-
member inline this.For(sequence: #seq<'T>, [<InlineIfLambda>] binder: 'T -> Job<_ option>) : Job<_ option> =
96+
member inline this.For
97+
(
98+
sequence: #seq<'T>,
99+
[<InlineIfLambda>] binder: 'T -> Job<_ option>
100+
) : Job<_ option> =
80101
this.Using(
81102
sequence.GetEnumerator(),
82103
fun enum -> this.While(enum.MoveNext, this.Delay(fun () -> binder enum.Current))
@@ -92,12 +113,16 @@ module JobOptionCE =
92113
/// <summary>
93114
/// Method lets us transform data types into our internal representation.
94115
/// </summary>
95-
member inline _.Source(async: Async<_ option>) : Job<_ option> = async |> Job.fromAsync
116+
member inline _.Source(async: Async<_ option>) : Job<_ option> =
117+
async
118+
|> Job.fromAsync
96119

97120
/// <summary>
98121
/// Method lets us transform data types into our internal representation.
99122
/// </summary>
100-
member inline _.Source(task: Task<_ option>) : Job<_ option> = task |> Job.awaitTask
123+
member inline _.Source(task: Task<_ option>) : Job<_ option> =
124+
task
125+
|> Job.awaitTask
101126

102127
let jobOption = JobOptionBuilder()
103128

@@ -121,14 +146,22 @@ module JobOptionCEExtensions =
121146
/// <summary>
122147
/// Method lets us transform data types into our internal representation.
123148
/// </summary>
124-
member inline _.Source(a: Job<'t>) = a |> Job.map Some
149+
member inline _.Source(a: Job<'t>) =
150+
a
151+
|> Job.map Some
125152

126153
/// <summary>
127154
/// Method lets us transform data types into our internal representation.
128155
/// </summary>
129-
member inline _.Source(a: Async<'t>) = a |> Job.fromAsync |> Job.map Some
156+
member inline _.Source(a: Async<'t>) =
157+
a
158+
|> Job.fromAsync
159+
|> Job.map Some
130160

131161
/// <summary>
132162
/// Method lets us transform data types into our internal representation.
133163
/// </summary>
134-
member inline _.Source(a: Task<'t>) = a |> Job.awaitTask |> Job.map Some
164+
member inline _.Source(a: Task<'t>) =
165+
a
166+
|> Job.awaitTask
167+
|> Job.map Some

src/FsToolkit.ErrorHandling.JobResult/JobResult.fs

Lines changed: 84 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,43 @@ module JobResult =
1111
let inline mapError ([<InlineIfLambda>] f) jr = Job.map (Result.mapError f) jr
1212

1313
let inline bind ([<InlineIfLambda>] f: 'a -> Job<Result<'c, 'b>>) (jr: Job<Result<'a, 'b>>) =
14-
Job.bind (Result.either f (Error >> Job.result)) jr
14+
Job.bind
15+
(Result.either
16+
f
17+
(Error
18+
>> Job.result))
19+
jr
1520

1621
let inline foldResult ([<InlineIfLambda>] onSuccess) ([<InlineIfLambda>] onError) jr =
1722
Job.map (Result.fold onSuccess onError) jr
1823

1924
let inline ofAsync aAsync =
20-
aAsync |> Job.fromAsync |> Job.catch |> Job.map Result.ofChoice
25+
aAsync
26+
|> Job.fromAsync
27+
|> Job.catch
28+
|> Job.map Result.ofChoice
2129

2230
let inline fromTask aTask =
23-
aTask |> Job.fromTask |> Job.catch |> Job.map Result.ofChoice
31+
aTask
32+
|> Job.fromTask
33+
|> Job.catch
34+
|> Job.map Result.ofChoice
2435

2536
let inline fromUnitTask aTask =
26-
aTask |> Job.fromUnitTask |> Job.catch |> Job.map Result.ofChoice
37+
aTask
38+
|> Job.fromUnitTask
39+
|> Job.catch
40+
|> Job.map Result.ofChoice
2741

28-
let inline retn x = Ok x |> Job.result
42+
let inline retn x =
43+
Ok x
44+
|> Job.result
2945

3046
let inline ok x = retn x
3147

32-
let inline returnError x = Error x |> Job.result
48+
let inline returnError x =
49+
Error x
50+
|> Job.result
3351

3452
let inline error x = returnError x
3553

@@ -59,7 +77,8 @@ module JobResult =
5977
/// The result if the result is Ok, else returns <paramref name="ifError"/>.
6078
/// </returns>
6179
let inline orElse (ifError: Job<Result<'ok, 'error2>>) (result: Job<Result<'ok, 'error>>) =
62-
result |> Job.bind (Result.either ok (fun _ -> ifError))
80+
result
81+
|> Job.bind (Result.either ok (fun _ -> ifError))
6382

6483
/// <summary>
6584
/// Returns <paramref name="result"/> if it is <c>Ok</c>, otherwise executes <paramref name="ifErrorFunc"/> and returns the result.
@@ -84,115 +103,146 @@ module JobResult =
84103
([<InlineIfLambda>] ifErrorFunc: 'error -> Job<Result<'ok, 'error2>>)
85104
(result: Job<Result<'ok, 'error>>)
86105
=
87-
result |> Job.bind (Result.either ok ifErrorFunc)
106+
result
107+
|> Job.bind (Result.either ok ifErrorFunc)
88108

89109
/// Replaces the wrapped value with unit
90-
let inline ignore<'ok, 'error> (jr: Job<Result<'ok, 'error>>) = jr |> map ignore<'ok>
110+
let inline ignore<'ok, 'error> (jr: Job<Result<'ok, 'error>>) =
111+
jr
112+
|> map ignore<'ok>
91113

92114
/// Returns the specified error if the job-wrapped value is false.
93115
let inline requireTrue error value =
94-
value |> Job.map (Result.requireTrue error)
116+
value
117+
|> Job.map (Result.requireTrue error)
95118

96119
/// Returns the specified error if the job-wrapped value is true.
97120
let inline requireFalse error value =
98-
value |> Job.map (Result.requireFalse error)
121+
value
122+
|> Job.map (Result.requireFalse error)
99123

100124
// Converts an job-wrapped Option to a Result, using the given error if None.
101125
let inline requireSome error option =
102-
option |> Job.map (Result.requireSome error)
126+
option
127+
|> Job.map (Result.requireSome error)
103128

104129
// Converts an job-wrapped Option to a Result, using the given error if Some.
105130
let inline requireNone error option =
106-
option |> Job.map (Result.requireNone error)
131+
option
132+
|> Job.map (Result.requireNone error)
107133

108134
/// Returns Ok if the job-wrapped value and the provided value are equal, or the specified error if not.
109135
let inline requireEqual x1 x2 error =
110-
x2 |> Job.map (fun x2' -> Result.requireEqual x1 x2' error)
136+
x2
137+
|> Job.map (fun x2' -> Result.requireEqual x1 x2' error)
111138

112139
/// Returns Ok if the two values are equal, or the specified error if not.
113140
let inline requireEqualTo other error this =
114-
this |> Job.map (Result.requireEqualTo other error)
141+
this
142+
|> Job.map (Result.requireEqualTo other error)
115143

116144
/// Returns Ok if the job-wrapped sequence is empty, or the specified error if not.
117145
let inline requireEmpty error xs =
118-
xs |> Job.map (Result.requireEmpty error)
146+
xs
147+
|> Job.map (Result.requireEmpty error)
119148

120149
/// Returns Ok if the job-wrapped sequence is not-empty, or the specified error if not.
121150
let inline requireNotEmpty error xs =
122-
xs |> Job.map (Result.requireNotEmpty error)
151+
xs
152+
|> Job.map (Result.requireNotEmpty error)
123153

124154
/// Returns the first item of the job-wrapped sequence if it exists, or the specified
125155
/// error if the sequence is empty
126156
let inline requireHead error xs =
127-
xs |> Job.map (Result.requireHead error)
157+
xs
158+
|> Job.map (Result.requireHead error)
128159

129160
/// Replaces an error value of an job-wrapped result with a custom error
130161
/// value.
131162
let inline setError error jobResult =
132-
jobResult |> Job.map (Result.setError error)
163+
jobResult
164+
|> Job.map (Result.setError error)
133165

134166
/// Replaces a unit error value of an job-wrapped result with a custom
135167
/// error value. Safer than setError since you're not losing any information.
136168
let inline withError error jobResult =
137-
jobResult |> Job.map (Result.withError error)
169+
jobResult
170+
|> Job.map (Result.withError error)
138171

139172
/// Extracts the contained value of an job-wrapped result if Ok, otherwise
140173
/// uses ifError.
141174
let inline defaultValue ifError jobResult =
142-
jobResult |> Job.map (Result.defaultValue ifError)
175+
jobResult
176+
|> Job.map (Result.defaultValue ifError)
143177

144178
/// Extracts the contained value of an job-wrapped result if Error, otherwise
145179
/// uses ifOk.
146180
let inline defaultError ifOk jobResult =
147-
jobResult |> Job.map (Result.defaultError ifOk)
181+
jobResult
182+
|> Job.map (Result.defaultError ifOk)
148183

149184
/// Extracts the contained value of an job-wrapped result if Ok, otherwise
150185
/// evaluates ifErrorThunk and uses the result.
151186
let inline defaultWith ifErrorThunk jobResult =
152-
jobResult |> Job.map (Result.defaultWith ifErrorThunk)
187+
jobResult
188+
|> Job.map (Result.defaultWith ifErrorThunk)
153189

154190
/// Same as defaultValue for a result where the Ok value is unit. The name
155191
/// describes better what is actually happening in this case.
156-
let inline ignoreError<'error> (jobResult: Job<Result<unit, 'error>>) = defaultValue () jobResult
192+
let inline ignoreError<'error> (jobResult: Job<Result<unit, 'error>>) =
193+
defaultValue () jobResult
157194

158195
/// If the job-wrapped result is Ok, executes the function on the Ok value.
159196
/// Passes through the input value.
160-
let inline tee ([<InlineIfLambda>] f) jobResult = jobResult |> Job.map (Result.tee f)
197+
let inline tee ([<InlineIfLambda>] f) jobResult =
198+
jobResult
199+
|> Job.map (Result.tee f)
161200

162201
/// If the job-wrapped result is Ok and the predicate returns true, executes
163202
/// the function on the Ok value. Passes through the input value.
164203
let inline teeIf ([<InlineIfLambda>] predicate) ([<InlineIfLambda>] f) jobResult =
165-
jobResult |> Job.map (Result.teeIf predicate f)
204+
jobResult
205+
|> Job.map (Result.teeIf predicate f)
166206

167207
/// If the job-wrapped result is Error, executes the function on the Error
168208
/// value. Passes through the input value.
169209
let inline teeError ([<InlineIfLambda>] f) jobResult =
170-
jobResult |> Job.map (Result.teeError f)
210+
jobResult
211+
|> Job.map (Result.teeError f)
171212

172213
/// If the job-wrapped result is Error and the predicate returns true,
173214
/// executes the function on the Error value. Passes through the input value.
174215
let inline teeErrorIf ([<InlineIfLambda>] predicate) ([<InlineIfLambda>] f) jobResult =
175-
jobResult |> Job.map (Result.teeErrorIf predicate f)
216+
jobResult
217+
|> Job.map (Result.teeErrorIf predicate f)
176218

177219
/// Takes two results and returns a tuple of the pair
178220
let inline zip j1 j2 =
179-
Job.zip j1 j2 |> Job.map (fun (r1, r2) -> Result.zip r1 r2)
221+
Job.zip j1 j2
222+
|> Job.map (fun (r1, r2) -> Result.zip r1 r2)
180223

181224
/// Takes two results and returns a tuple of the error pair
182225
let inline zipError j1 j2 =
183-
Job.zip j1 j2 |> Job.map (fun (r1, r2) -> Result.zipError r1 r2)
226+
Job.zip j1 j2
227+
|> Job.map (fun (r1, r2) -> Result.zipError r1 r2)
184228

185229
/// Catches exceptions and maps them to the Error case using the provided function.
186230
let inline catch f x =
187231
x
188232
|> Job.catch
189-
|> Job.map (function
233+
|> Job.map (
234+
function
190235
| Choice1Of2 (Ok v) -> Ok v
191236
| Choice1Of2 (Error err) -> Error err
192-
| Choice2Of2 ex -> Error(f ex))
237+
| Choice2Of2 ex -> Error(f ex)
238+
)
193239

194240
/// Lift Job to JobResult
195-
let inline ofJob x = x |> Job.map Ok
241+
let inline ofJob x =
242+
x
243+
|> Job.map Ok
196244

197245
/// Lift Result to JobResult
198-
let inline ofResult (x: Result<_, _>) = x |> Job.singleton
246+
let inline ofResult (x: Result<_, _>) =
247+
x
248+
|> Job.singleton

0 commit comments

Comments
 (0)