Skip to content

Commit 726b20b

Browse files
authored
Rename Sequence overloads to Sequential (#595)
1 parent d6de56b commit 726b20b

File tree

2 files changed

+60
-42
lines changed

2 files changed

+60
-42
lines changed

src/FSharpPlus/Control/Traversable.fs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -188,26 +188,26 @@ type Sequence with
188188
static member inline Sequence (t: seq<'``Applicative<'T>``>, [<Optional>]_output: '``Applicative<seq<'T>>`` , [<Optional>]_impl: Default4) : '``Applicative<seq<'T>>`` =
189189
Sequence.ForInfiniteSequences (t, IsLeftZero.Invoke, List.toSeq)
190190

191-
static member Sequence (t: seq<option<'t>> , [<Optional>]_output: option<seq<'t>> , [<Optional>]_impl: Default3) : option<seq<'t>> = Option.Sequence t
191+
static member Sequence (t: seq<option<'t>> , [<Optional>]_output: option<seq<'t>> , [<Optional>]_impl: Default3) : option<seq<'t>> = Option.Sequential t
192192
#if !FABLE_COMPILER
193-
static member Sequence (t: seq<voption<'t>> , [<Optional>]_output: voption<seq<'t>> , [<Optional>]_impl: Default3) : voption<seq<'t>> = ValueOption.Sequence t
193+
static member Sequence (t: seq<voption<'t>> , [<Optional>]_output: voption<seq<'t>> , [<Optional>]_impl: Default3) : voption<seq<'t>> = ValueOption.Sequential t
194194
#endif
195-
static member Sequence (t: seq<Result<'t,'e>>, [<Optional>]_output: Result<seq<'t>, 'e>, [<Optional>]_impl: Default3) : Result<seq<'t>, 'e> = Result.Sequence t
196-
static member Sequence (t: seq<Choice<'t,'e>>, [<Optional>]_output: Choice<seq<'t>, 'e>, [<Optional>]_impl: Default3) : Choice<seq<'t>, 'e> = Choice.Sequence t
195+
static member Sequence (t: seq<Result<'t,'e>>, [<Optional>]_output: Result<seq<'t>, 'e>, [<Optional>]_impl: Default3) : Result<seq<'t>, 'e> = Result.Sequential t
196+
static member Sequence (t: seq<Choice<'t,'e>>, [<Optional>]_output: Choice<seq<'t>, 'e>, [<Optional>]_impl: Default3) : Choice<seq<'t>, 'e> = Choice.Sequential t
197197
static member Sequence (t: seq<list<'t>> , [<Optional>]_output: list<seq<'t>> , [<Optional>]_impl: Default3) : list<seq<'t>> = Sequence.ForInfiniteSequences (t, List.isEmpty, List.toSeq)
198198
static member Sequence (t: seq<'t []> , [<Optional>]_output: seq<'t> [] , [<Optional>]_impl: Default3) : seq<'t> [] = Sequence.ForInfiniteSequences (t, Array.isEmpty, List.toSeq)
199199

200200
#if !FABLE_COMPILER
201-
static member Sequence (t: seq<Async<'t>> , [<Optional>]_output: Async<seq<'t>> , [<Optional>]_impl: Default3) : Async<seq<'t>> = Async.Sequence t
201+
static member Sequence (t: seq<Async<'t>> , [<Optional>]_output: Async<seq<'t>> , [<Optional>]_impl: Default3) : Async<seq<'t>> = Async.SequentialLazy t
202202
#endif
203203
static member inline Sequence (t: NonEmptySeq<'``Applicative<'T>``>, [<Optional>]_output: '``Applicative<NonEmptySeq<'T>>`` , [<Optional>]_impl: Default4) : '``Applicative<NonEmptySeq<'T>>`` = Sequence.ForInfiniteSequences (t, IsLeftZero.Invoke, NonEmptySeq.ofList)
204-
static member Sequence (t: NonEmptySeq<option<'t>> , [<Optional>]_output: option<NonEmptySeq<'t>> , [<Optional>]_impl: Default3) : option<NonEmptySeq<'t>> = Option.Sequence t |> Option.map NonEmptySeq.unsafeOfSeq
205-
static member Sequence (t: NonEmptySeq<Result<'t,'e>>, [<Optional>]_output: Result<NonEmptySeq<'t>, 'e>, [<Optional>]_impl: Default3) : Result<NonEmptySeq<'t>, 'e> = Result.Sequence t |> Result.map NonEmptySeq.unsafeOfSeq
206-
static member Sequence (t: NonEmptySeq<Choice<'t,'e>>, [<Optional>]_output: Choice<NonEmptySeq<'t>, 'e>, [<Optional>]_impl: Default3) : Choice<NonEmptySeq<'t>, 'e> = Choice.Sequence t |> Choice.map NonEmptySeq.unsafeOfSeq
204+
static member Sequence (t: NonEmptySeq<option<'t>> , [<Optional>]_output: option<NonEmptySeq<'t>> , [<Optional>]_impl: Default3) : option<NonEmptySeq<'t>> = Option.Sequential t |> Option.map NonEmptySeq.unsafeOfSeq
205+
static member Sequence (t: NonEmptySeq<Result<'t,'e>>, [<Optional>]_output: Result<NonEmptySeq<'t>, 'e>, [<Optional>]_impl: Default3) : Result<NonEmptySeq<'t>, 'e> = Result.Sequential t |> Result.map NonEmptySeq.unsafeOfSeq
206+
static member Sequence (t: NonEmptySeq<Choice<'t,'e>>, [<Optional>]_output: Choice<NonEmptySeq<'t>, 'e>, [<Optional>]_impl: Default3) : Choice<NonEmptySeq<'t>, 'e> = Choice.Sequential t |> Choice.map NonEmptySeq.unsafeOfSeq
207207
static member Sequence (t: NonEmptySeq<list<'t>> , [<Optional>]_output: list<NonEmptySeq<'t>> , [<Optional>]_impl: Default3) : list<NonEmptySeq<'t>> = Sequence.ForInfiniteSequences(t, List.isEmpty , NonEmptySeq.ofList)
208208
static member Sequence (t: NonEmptySeq<'t []> , [<Optional>]_output: NonEmptySeq<'t> [] , [<Optional>]_impl: Default3) : NonEmptySeq<'t> [] = Sequence.ForInfiniteSequences(t, Array.isEmpty, NonEmptySeq.ofList)
209209
#if !FABLE_COMPILER
210-
static member Sequence (t: NonEmptySeq<Async<'t>> , [<Optional>]_output: Async<NonEmptySeq<'t>> , [<Optional>]_impl: Default3) = Async.Sequence t |> Async.map NonEmptySeq.unsafeOfSeq : Async<NonEmptySeq<'t>>
210+
static member Sequence (t: NonEmptySeq<Async<'t>> , [<Optional>]_output: Async<NonEmptySeq<'t>> , [<Optional>]_impl: Default3) = Async.SequentialLazy t |> Async.map NonEmptySeq.unsafeOfSeq : Async<NonEmptySeq<'t>>
211211
#endif
212212

213213
static member inline Sequence (t: ^a , [<Optional>]_output: 'R, [<Optional>]_impl: Default2) : 'R = Traverse.InvokeOnInstance id t
@@ -431,9 +431,9 @@ type Transpose with
431431
static member inline Transpose (t: seq<'``Applicative<'T>``>, [<Optional>]_output: '``Applicative<seq<'T>>`` , [<Optional>]_impl: Default4) : '``Applicative<seq<'T>>`` =
432432
Transpose.ForInfiniteSequences (t, IsZipLeftZero.Invoke, List.toSeq, Pure.Invoke)
433433

434-
static member Transpose (t: seq<option<'t>> , [<Optional>]_output: option<seq<'t>> , [<Optional>]_impl: Default3) : option<seq<'t>> = Option.Sequence t
434+
static member Transpose (t: seq<option<'t>> , [<Optional>]_output: option<seq<'t>> , [<Optional>]_impl: Default3) : option<seq<'t>> = Option.Sequential t
435435
#if !FABLE_COMPILER
436-
static member Transpose (t: seq<voption<'t>> , [<Optional>]_output: voption<seq<'t>> , [<Optional>]_impl: Default3) : voption<seq<'t>> = ValueOption.Sequence t
436+
static member Transpose (t: seq<voption<'t>> , [<Optional>]_output: voption<seq<'t>> , [<Optional>]_impl: Default3) : voption<seq<'t>> = ValueOption.Sequential t
437437
#endif
438438
static member inline Transpose (t: seq<Result<'t,'e>>, [<Optional>]_output: Result<seq<'t>, 'e>, [<Optional>]_impl: Default3) : Result<seq<'t>, 'e> = Result.Parallel ((++), t)
439439
static member inline Transpose (t: seq<Choice<'t,'e>>, [<Optional>]_output: Choice<seq<'t>, 'e>, [<Optional>]_impl: Default3) : Choice<seq<'t>, 'e> = Choice.Parallel ((++), t)
@@ -443,7 +443,7 @@ type Transpose with
443443
static member Transpose (t: seq<Async<'t>> , [<Optional>]_output: Async<seq<'t>> , [<Optional>]_impl: Default3) : Async<seq<'t>> = Async.Parallel t |> Async.map Array.toSeq
444444
#endif
445445
static member inline Transpose (t: NonEmptySeq<'``Applicative<'T>``>, [<Optional>]_output: '``Applicative<NonEmptySeq<'T>>``, [<Optional>]_impl: Default4) : '``Applicative<NonEmptySeq<'T>>`` = Transpose.ForInfiniteSequences (t, IsZipLeftZero.Invoke, NonEmptySeq.ofList, fun _ -> Unchecked.defaultof<_>)
446-
static member Transpose (t: NonEmptySeq<option<'t>> , [<Optional>]_output: option<NonEmptySeq<'t>> , [<Optional>]_impl: Default3) : option<NonEmptySeq<'t>> = Option.Sequence t |> Option.map NonEmptySeq.unsafeOfSeq
446+
static member Transpose (t: NonEmptySeq<option<'t>> , [<Optional>]_output: option<NonEmptySeq<'t>> , [<Optional>]_impl: Default3) : option<NonEmptySeq<'t>> = Option.Sequential t |> Option.map NonEmptySeq.unsafeOfSeq
447447
static member inline Transpose (t: NonEmptySeq<Result<'t,'e>>, [<Optional>]_output: Result<NonEmptySeq<'t>, 'e>, [<Optional>]_impl: Default3) : Result<NonEmptySeq<'t>, 'e> = Result.Parallel ((++), t) |> Result.map NonEmptySeq.unsafeOfSeq
448448
static member inline Transpose (t: NonEmptySeq<Choice<'t,'e>>, [<Optional>]_output: Choice<NonEmptySeq<'t>, 'e>, [<Optional>]_impl: Default3) : Choice<NonEmptySeq<'t>, 'e> = Choice.Parallel ((++), t) |> Choice.map NonEmptySeq.unsafeOfSeq
449449
static member Transpose (t: NonEmptySeq<list<'t>> , [<Optional>]_output: list<NonEmptySeq<'t>> , [<Optional>]_impl: Default3) : list<NonEmptySeq<'t>> = Transpose.ForInfiniteSequences (t, List.isEmpty , NonEmptySeq.ofList, fun _ -> Unchecked.defaultof<_>)

src/FSharpPlus/Extensions/Extensions.fs

Lines changed: 48 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)