@@ -173,15 +173,16 @@ module Extensions =
173173 |> ignore)
174174
175175
176-
177176 /// Combine all asyncs in one, chaining them in sequence order.
178- static member Sequence ( t : seq < Async < 'T >>) : Async < seq < _ >> = async {
177+ /// Similar to Async.Sequential but the returned Async contains a sequence, which is lazily evaluated.
178+ static member SequentialLazy ( t : seq < Async < 'T >>) : Async < seq < _ >> = async {
179179 let! ct = Async.CancellationToken
180180 return Seq.map ( fun t -> Async.AsTask( t, ct). Result) t }
181+ [<Obsolete( " Renamed to Async.Sequential or Async.SequentialLazy" ) >] static member Sequence ( t : seq < Async < _ >>) = Async.SequentialLazy t
181182 #endif
182183
183184 /// Combine all asyncs in one, chaining them in sequence order.
184- static member Sequence ( t : list < Async < 'T >>) : Async < list < 'T >> =
185+ static member Sequential ( t : list < Async < 'T >>) : Async < list < 'T >> =
185186 #if FABLE_ COMPILER
186187 let rec loop acc = function
187188 | [] -> async.Return ( List.rev acc)
@@ -195,44 +196,56 @@ module Extensions =
195196 coll.Add v
196197 return coll.Close () }
197198 #endif
199+ [<Obsolete( " Renamed to Async.Sequential" ) >] static member Sequence ( t : list < Async < 'T >>) = Async<_>. Sequential t
200+
198201
199202 /// Combine all asyncs in one, chaining them in sequence order.
200- static member Sequence ( t : array < Async < _ >>) : Async < array < _ >> = async {
203+ static member Sequential ( t : array < Async < _ >>) : Async < array < _ >> = async {
201204 let siz = Array.length t
202205 let arr = Array.zeroCreate siz
203206 for i in 0 .. siz-1 do
204207 let! v = t.[ i]
205208 arr.[ i] <- v
206209 return arr }
210+ [<Obsolete( " Renamed to Async.Sequential" ) >] static member Sequence ( t : array < Async < _ >>) = Async<_>. Sequential t
211+
207212
208213 /// Creates an async Result from a Result where the Ok case is async.
209- static member Sequence ( t : Result < Async < 'T >, 'Error >) : Async < Result < 'T , 'Error >> =
214+ static member Sequential ( t : Result < Async < 'T >, 'Error >) : Async < Result < 'T , 'Error >> =
210215 match t with
211216 | Ok a -> Async.Map Ok a
212217 | Error e -> async.Return ( Error e)
218+ [<Obsolete( " Renamed to Async.Sequential" ) >] static member Sequence ( t : Result < Async < 'T >, 'Error >) = Async<_>. Sequential t
219+
213220
214221 /// Creates an async Choice from a Choice where the Choice1Of2 case is async.
215- static member Sequence ( t : Choice < Async < 'T >, 'Choice2Of2 >) : Async < Choice < 'T , 'Choice2Of2 >> =
222+ static member Sequential ( t : Choice < Async < 'T >, 'Choice2Of2 >) : Async < Choice < 'T , 'Choice2Of2 >> =
216223 match t with
217224 | Choice1Of2 a -> Async.Map Choice1Of2 a
218225 | Choice2Of2 e -> async.Return ( Choice2Of2 e)
226+ [<Obsolete( " Renamed to Async.Sequential" ) >] static member Sequence ( t : Choice < Async < 'T >, 'Choice2Of2 >) = Async<_>. Sequential t
227+
219228
220229 /// Creates an async Result from a Result where both cases are async.
221- static member Bisequence ( t : Result < Async < 'T >, Async < 'Error >>) : Async < Result < 'T , 'Error >> =
230+ static member Bisequential ( t : Result < Async < 'T >, Async < 'Error >>) : Async < Result < 'T , 'Error >> =
222231 match t with
223232 | Ok a -> Async.Map Ok a
224233 | Error e -> Async.Map Error e
234+ [<Obsolete( " Renamed to Async.Bisequential" ) >] static member Bisequence ( t : Result < Async < 'T >, Async < 'Error >>) = Async.Bisequential t
235+
225236
226237 /// Creates an async Choice from a Choice where both cases are async.
227- static member Bisequence ( t : Choice < Async < 'T >, Async < 'Choice2Of2 >>) : Async < Choice < 'T , 'Choice2Of2 >> =
238+ static member Bisequential ( t : Choice < Async < 'T >, Async < 'Choice2Of2 >>) : Async < Choice < 'T , 'Choice2Of2 >> =
228239 match t with
229240 | Choice1Of2 a -> Async.Map Choice1Of2 a
230241 | Choice2Of2 e -> Async.Map Choice2Of2 e
242+ [<Obsolete( " Renamed to Async.Bisequential" ) >] static member Bisequence ( t : Choice < Async < 'T >, Async < 'Choice2Of2 >>) = Async.Bisequential t
243+
231244
232245 type Option < 't > with
233246
234- /// Returns None if it contains a None element, otherwise a list of all elements
235- static member Sequence ( t : seq < option < 't >>) =
247+ /// Returns None if it contains a None element, otherwise a list of all elements.
248+ static member Sequential ( t : seq < option < 't >>) =
236249 #if FABLE_ COMPILER
237250 let mutable ok = true
238251 let res = Seq.toArray ( seq {
@@ -253,14 +266,15 @@ module Extensions =
253266
254267 if noneFound
255268 then None
256- else
257- Some ( accumulator.Close () |> Array.toSeq)
269+ else accumulator.Close () |> Array.toSeq |> Some
258270 #endif
271+ [<Obsolete( " Renamed to Option.Sequential" ) >] static member Sequence ( t : seq < option < 't >>) = Option.Sequential t
259272
273+
260274 type ValueOption < 't > with
261275
262- /// Returns None if it contains a None element, otherwise a list of all elements
263- static member Sequence ( t : seq < voption < 't >>) =
276+ /// Returns None if it contains a None element, otherwise a list of all elements.
277+ static member Sequential ( t : seq < voption < 't >>) =
264278 #if FABLE_ COMPILER
265279 let mutable ok = true
266280 let res = Seq.toArray ( seq {
@@ -281,14 +295,15 @@ module Extensions =
281295
282296 if noneFound
283297 then ValueNone
284- else
285- ValueSome ( accumulator.Close () |> Array.toSeq)
298+ else accumulator.Close () |> Array.toSeq |> ValueSome
286299 #endif
300+ [<Obsolete( " Renamed to ValueOption.Sequential" ) >] static member Sequence ( t : seq < voption < 't >>) = ValueOption.Sequential t
301+
287302
288- type Choice < 't , 'error > with
303+ type Choice < 'T1 , 'T2 > with
289304
290- /// Returns the first Error if it contains an Error element, otherwise a list of all elements
291- static member Sequence ( t : seq < Choice < _ , _ >>) =
305+ /// Returns the first Choice2Of2 if it contains a Choice2Of2 element, otherwise a list of all Choice1Of2 elements.
306+ static member Sequential ( t : seq < Choice < 'T1 , 'T2 >>) =
292307 #if FABLE_ COMPILER
293308 let mutable error = ValueNone
294309 let res = Seq.toArray ( seq {
@@ -302,7 +317,7 @@ module Extensions =
302317 | ValueNone -> Choice1Of2 ( Array.toSeq res)
303318 | ValueSome e -> Choice2Of2 e
304319 #else
305- let mutable accumulator = ArrayCollector< 't > ()
320+ let mutable accumulator = ArrayCollector< 'T1 > ()
306321 let mutable error = ValueNone
307322 use e = t.GetEnumerator ()
308323 while e.MoveNext () && error.IsNone do
@@ -313,28 +328,30 @@ module Extensions =
313328 | ValueNone -> Choice1Of2 ( accumulator.Close () |> Array.toSeq)
314329 | ValueSome x -> Choice2Of2 x
315330 #endif
331+ [<Obsolete( " Renamed to Choice.Sequential" ) >] static member Sequence ( t : seq < Choice < _ , _ >>) = Choice<_, _>. Sequential t
316332
317- /// Returns all Errors combined, otherwise a sequence of all elements.
318- static member Parallel ( combiner , t : seq < Choice < _ , _ >>) =
333+
334+ /// Returns all Choice2Of2's combined, otherwise a sequence of all Choice1Of2 elements.
335+ static member Parallel ( choice2Combiner , t : seq < Choice < 'T1 , 'T2 >>) =
319336 let mutable error = ValueNone
320337 let res = Seq.toArray ( seq {
321338 use e = t.GetEnumerator ()
322339 while e.MoveNext () do
323340 match e.Current, error with
324341 | Choice1Of2 v, ValueNone -> yield v
325342 | Choice2Of2 e, ValueNone -> error <- ValueSome e
326- | Choice2Of2 e, ValueSome x -> error <- ValueSome ( combiner x e)
343+ | Choice2Of2 e, ValueSome x -> error <- ValueSome ( choice2Combiner x e)
327344 | _ -> () })
328345
329346 match error with
330347 | ValueNone -> Choice1Of2 ( Array.toSeq res)
331348 | ValueSome e -> Choice2Of2 e
332349
333350
334- type Result < 't , 'error > with
351+ type Result < 'T , 'Error > with
335352
336- /// Returns the first Error if it contains an Error element, otherwise a list of all elements
337- static member Sequence ( t : seq < Result < _ , _ >>) =
353+ /// Returns the first Error if it contains an Error element, otherwise a sequence of all elements.
354+ static member Sequential ( t : seq < Result < 'T , 'Error >>) =
338355 #if FABLE_ COMPILER
339356 let mutable error = ValueNone
340357 let res = Seq.toArray ( seq {
@@ -348,7 +365,7 @@ module Extensions =
348365 | ValueNone -> Ok ( Array.toSeq res)
349366 | ValueSome e -> Error e
350367 #else
351- let mutable accumulator = ArrayCollector< 't > ()
368+ let mutable accumulator = ArrayCollector< 'T > ()
352369 let mutable error = ValueNone
353370 use e = t.GetEnumerator ()
354371 while e.MoveNext () && error.IsNone do
@@ -359,18 +376,19 @@ module Extensions =
359376 | ValueNone -> Ok ( accumulator.Close () |> Array.toSeq)
360377 | ValueSome x -> Error x
361378 #endif
379+ [<Obsolete( " Renamed to Result.Sequential" ) >] static member Sequence ( t : seq < Result < _ , _ >>) = Result.Sequential t
362380
363381 /// Returns all Errors combined, otherwise a sequence of all elements.
364- static member Parallel ( combiner , t : seq < Result < _ , _ >>) =
382+ static member Parallel ( errorCombiner , t : seq < Result < 'T , 'Error >>) =
365383 let mutable error = ValueNone
366384 let res = Seq.toArray ( seq {
367385 use e = t.GetEnumerator ()
368386 while e.MoveNext () do
369387 match e.Current, error with
370388 | Ok v , ValueNone -> yield v
371389 | Error e, ValueNone -> error <- ValueSome e
372- | Error e, ValueSome x -> error <- ValueSome ( combiner x e)
373- | _ -> () })
390+ | Error e, ValueSome x -> error <- ValueSome ( errorCombiner x e)
391+ | _ -> () })
374392
375393 match error with
376394 | ValueNone -> Ok ( Array.toSeq res)
0 commit comments