Skip to content

Commit 2b08e0f

Browse files
committed
Enable/optimize NonEmpty traversals
1 parent 28d6e4f commit 2b08e0f

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

src/FSharpPlus/Control/Traversable.fs

+13-13
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ type ParSequence =
254254
static member inline InvokeOnInstance (t: '``ParTraversable<'Functor<'T>>``) = (^``ParTraversable<'Functor<'T>>`` : (static member ParSequence : _ -> _) t) : '``Functor<'ParTraversable<'T>>``
255255

256256
[<EditorBrowsable(EditorBrowsableState.Never)>]
257-
static member inline ForInfiniteSequences (t: seq<_>, isFailure, conversion) =
257+
static member inline ForInfiniteSequences (t: seq<_>, [<InlineIfLambda>]isFailure, [<InlineIfLambda>]conversion, [<InlineIfLambda>]result) =
258258
let add x y = y :: x
259259
let mutable go = true
260260
let mutable r = Unchecked.defaultof<_>
@@ -265,7 +265,7 @@ type ParSequence =
265265
if isEmpty then r <- Map.Invoke List.singleton e.Current
266266
else r <- Map.Invoke add r </> e.Current
267267
isEmpty <- false
268-
if isEmpty then ParReturn.Invoke (conversion [])
268+
if isEmpty then result (conversion [])
269269
else Map.Invoke (List.rev >> conversion) r
270270

271271
type ParTraverse =
@@ -306,14 +306,14 @@ type ParTraverse =
306306
Traces.add "ParTraverse seq, 'T -> Functor<'U>"
307307
#endif
308308
let mapped = Seq.map f t
309-
ParSequence.ForInfiniteSequences (mapped, IsParLeftZero.Invoke, List.toSeq) : '``Functor<seq<'U>>``
309+
ParSequence.ForInfiniteSequences (mapped, IsParLeftZero.Invoke, List.toSeq, Return.Invoke) : '``Functor<seq<'U>>``
310310

311311
static member inline ParTraverse (t: NonEmptySeq<'T>, f: 'T -> '``Functor<'U>``, [<Optional>]_output: '``Functor<NonEmptySeq<'U>>``, [<Optional>]_impl: Default2) =
312312
#if TEST_TRACE
313313
Traces.add "ParTraverse NonEmptySeq, 'T -> Functor<'U>"
314314
#endif
315315
let mapped = NonEmptySeq.map f t
316-
ParSequence.ForInfiniteSequences (mapped, IsParLeftZero.Invoke, NonEmptySeq.ofList) : '``Functor<NonEmptySeq<'U>>``
316+
ParSequence.ForInfiniteSequences (mapped, IsParLeftZero.Invoke, NonEmptySeq.ofList, Return.Invoke) : '``Functor<NonEmptySeq<'U>>``
317317

318318
static member inline ParTraverse (t: ^a, f, [<Optional>]_output: 'R, [<Optional>]_impl: Default1) : 'R =
319319
#if TEST_TRACE
@@ -429,26 +429,26 @@ type ParSequence with
429429
Seq.foldBack cons_f t (ParReturn.Invoke Seq.empty)
430430

431431
static member inline ParSequence (t: seq<'``Applicative<'T>``>, [<Optional>]_output: '``Applicative<seq<'T>>`` , [<Optional>]_impl: Default4) : '``Applicative<seq<'T>>`` =
432-
ParSequence.ForInfiniteSequences (t, IsParLeftZero.Invoke, List.toSeq)
432+
ParSequence.ForInfiniteSequences (t, IsParLeftZero.Invoke, List.toSeq, Return.Invoke)
433433

434434
static member ParSequence (t: seq<option<'t>> , [<Optional>]_output: option<seq<'t>> , [<Optional>]_impl: Default3) : option<seq<'t>> = Option.Sequence t
435435
#if !FABLE_COMPILER
436436
static member ParSequence (t: seq<voption<'t>> , [<Optional>]_output: voption<seq<'t>> , [<Optional>]_impl: Default3) : voption<seq<'t>> = ValueOption.Sequence t
437437
#endif
438438
static member inline ParSequence (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 ParSequence (t: seq<Choice<'t,'e>>, [<Optional>]_output: Choice<seq<'t>, 'e>, [<Optional>]_impl: Default3) : Choice<seq<'t>, 'e> = Choice.Parallel ((++), t)
440-
static member ParSequence (t: seq<list<'t>> , [<Optional>]_output: list<seq<'t>> , [<Optional>]_impl: Default3) : list<seq<'t>> = ParSequence.ForInfiniteSequences (t, List.isEmpty, List.toSeq)
440+
static member ParSequence (t: seq<list<'t>> , [<Optional>]_output: list<seq<'t>> , [<Optional>]_impl: Default3) : list<seq<'t>> = ParSequence.ForInfiniteSequences (t, List.isEmpty, List.toSeq, List.singleton >> List.cycle)
441441
// static member ParSequence (t: seq<'t []> , [<Optional>]_output: seq<'t> [] , [<Optional>]_impl: Default3) : seq<'t> [] = ParSequence.ForInfiniteSequences (t, Array.isEmpty, List.toSeq)
442442

443443
#if !FABLE_COMPILER
444444
static member ParSequence (t: seq<Async<'t>> , [<Optional>]_output: Async<seq<'t>> , [<Optional>]_impl: Default3) : Async<seq<'t>> = Async.Parallel t |> Async.map Array.toSeq
445445
#endif
446-
static member inline ParSequence (t: NonEmptySeq<'``Applicative<'T>``>, [<Optional>]_output: '``Applicative<NonEmptySeq<'T>>`` , [<Optional>]_impl: Default4) : '``Applicative<NonEmptySeq<'T>>`` = ParSequence.ForInfiniteSequences (t, IsParLeftZero.Invoke, NonEmptySeq.ofList)
446+
static member inline ParSequence (t: NonEmptySeq<'``Applicative<'T>``>, [<Optional>]_output: '``Applicative<NonEmptySeq<'T>>``, [<Optional>]_impl: Default4) : '``Applicative<NonEmptySeq<'T>>`` = ParSequence.ForInfiniteSequences (t, IsParLeftZero.Invoke, NonEmptySeq.ofList, fun _ -> Unchecked.defaultof<_>)
447447
static member ParSequence (t: NonEmptySeq<option<'t>> , [<Optional>]_output: option<NonEmptySeq<'t>> , [<Optional>]_impl: Default3) : option<NonEmptySeq<'t>> = Option.Sequence t |> Option.map NonEmptySeq.unsafeOfSeq
448448
static member inline ParSequence (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
449449
static member inline ParSequence (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
450-
static member ParSequence (t: NonEmptySeq<list<'t>> , [<Optional>]_output: list<NonEmptySeq<'t>> , [<Optional>]_impl: Default3) : list<NonEmptySeq<'t>> = ParSequence.ForInfiniteSequences(t, List.isEmpty , NonEmptySeq.ofList)
451-
// static member ParSequence (t: NonEmptySeq<'t []> , [<Optional>]_output: NonEmptySeq<'t> [] , [<Optional>]_impl: Default3) : NonEmptySeq<'t> [] = ParSequence.ForInfiniteSequences(t, Array.isEmpty, NonEmptySeq.ofList)
450+
static member ParSequence (t: NonEmptySeq<list<'t>> , [<Optional>]_output: list<NonEmptySeq<'t>> , [<Optional>]_impl: Default3) : list<NonEmptySeq<'t>> = ParSequence.ForInfiniteSequences (t, List.isEmpty , NonEmptySeq.ofList, fun _ -> Unchecked.defaultof<_>)
451+
static member ParSequence (t: NonEmptySeq<'t []> , [<Optional>]_output: NonEmptySeq<'t> [] , [<Optional>]_impl: Default3) : NonEmptySeq<'t> [] = ParSequence.ForInfiniteSequences (t, Array.isEmpty, NonEmptySeq.ofList, fun _ -> Unchecked.defaultof<_>)
452452
#if !FABLE_COMPILER
453453
static member ParSequence (t: NonEmptySeq<Async<'t>> , [<Optional>]_output: Async<NonEmptySeq<'t>> , [<Optional>]_impl: Default3) = Async.Parallel t |> Async.map NonEmptySeq.unsafeOfSeq : Async<NonEmptySeq<'t>>
454454
#endif
@@ -460,7 +460,7 @@ type ParSequence with
460460
#if !FABLE_COMPILER
461461
static member inline ParSequence (t: voption<_>, [<Optional>]_output: 'R, [<Optional>]_impl: ParSequence) : 'R = match t with ValueSome x -> Map.Invoke ValueSome x | _ -> ParReturn.Invoke ValueNone
462462
#endif
463-
static member inline ParSequence (t: list<_> , [<Optional>]_output: 'R, [<Optional>]_impl: ParSequence) : 'R = ParSequence.ForInfiniteSequences(t, IsParLeftZero.Invoke, id)
463+
static member inline ParSequence (t: list<_> , [<Optional>]_output: 'R, [<Optional>]_impl: ParSequence) : 'R = ParSequence.ForInfiniteSequences (t, IsParLeftZero.Invoke, id, Return.Invoke)
464464

465465
static member inline ParSequence (t: Map<_,_> , [<Optional>]_output: 'R, [<Optional>]_impl: ParSequence) : 'R =
466466
let insert_f k x ys = Map.Invoke (Map.add k) x </> ys
@@ -476,11 +476,11 @@ type ParSequence with
476476
| Choice1Of2 a -> Map.Invoke Choice<'T,'Error>.Choice1Of2 a
477477
| Choice2Of2 e -> ParReturn.Invoke (Choice<'T,'Error>.Choice2Of2 e)
478478

479-
static member inline ParSequence (t: _ [] , [<Optional>]_output: 'R , [<Optional>]_impl: ParSequence) : 'R = ParSequence.ForInfiniteSequences(t, IsParLeftZero.Invoke, Array.ofList)
479+
static member inline ParSequence (t: _ [] , [<Optional>]_output: 'R , [<Optional>]_impl: ParSequence) : 'R = ParSequence.ForInfiniteSequences (t, IsParLeftZero.Invoke, Array.ofList, Return.Invoke)
480480

481-
static member inline ParSequence (t: Id<'``Functor<'T>``> , [<Optional>]_output: '``Functor<Id<'T>>`` , [<Optional>]_impl: ParSequence) : '``Functor<Id<'T>>`` = ParTraverse.Invoke id t
481+
static member inline ParSequence (t: Id<'``Functor<'T>``> , [<Optional>]_output: '``Functor<Id<'T>>`` , [<Optional>]_impl: ParSequence) : '``Functor<Id<'T>>`` = ParTraverse.Invoke id t
482482

483-
static member inline ParSequence (t: ResizeArray<'``Functor<'T>``>, [<Optional>]_output: '``Functor<ResizeArray<'T>>`` , [<Optional>]_impl: ParSequence) : '``Functor<ResizeArray<'T>>``= ParTraverse.Invoke id t
483+
static member inline ParSequence (t: ResizeArray<'``Functor<'T>``>, [<Optional>]_output: '``Functor<ResizeArray<'T>>``, [<Optional>]_impl: ParSequence) : '``Functor<ResizeArray<'T>>``= ParTraverse.Invoke id t
484484

485485
static member inline Invoke (t: '``ParTraversable<'Applicative<'T>>``) : '``Applicative<'ParTraversable<'T>>`` =
486486
let inline call_3 (a: ^a, b: ^b, c: ^c) = ((^a or ^b or ^c) : (static member ParSequence : _*_*_ -> _) b, c, a)

0 commit comments

Comments
 (0)