Skip to content

Commit 794c0ae

Browse files
committed
Try fix
1 parent 84f0151 commit 794c0ae

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

src/FSharpPlus/Data/NonEmptySeq.fs

+25-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ open System.Runtime.InteropServices
55
open System.ComponentModel
66
open System.Collections.Generic
77
open FSharpPlus
8+
open FSharpPlus.Extensions
89
open FSharpPlus.Control
10+
open Microsoft.FSharp.Core.CompilerServices
911

1012
/// A type-safe sequence that contains at least one element.
1113
[<Interface>]
@@ -78,24 +80,42 @@ type NonEmptySeq<'t> =
7880

7981

8082
static member inline Traverse (t: _ seq, f) =
81-
let cons x y = seq {yield x; yield! y}
82-
let cons_f x ys = Map.Invoke (cons: 'a->seq<_>->seq<_>) (f x) <*> ys
83-
Map.Invoke NonEmptySeq<_>.unsafeOfSeq (Seq.foldBack cons_f t (result Seq.empty))
83+
let cons x y = seq {yield x; yield! y}
84+
let cons_f x ys = Map.Invoke (cons: 'a->seq<_>->seq<_>) (f x) <*> ys
85+
Map.Invoke NonEmptySeq<_>.unsafeOfSeq (Seq.foldBack cons_f t (result Seq.empty))
8486

8587
static member inline Traverse (t: NonEmptySeq<'T>, f: 'T->'``Functor<'U>``) =
8688
let mapped = NonEmptySeq<_>.map f t
8789
Sequence.ForInfiniteSequences (mapped, IsLeftZero.Invoke, NonEmptySeq<_>.ofList) : '``Functor<NonEmptySeq<'U>>``
8890

8991
#if !FABLE_COMPILER
90-
static member Traverse (t: 't NonEmptySeq, f: 't->Async<'u>) : Async<NonEmptySeq<_>> = async {
92+
static member Traverse (t: 'T NonEmptySeq, f: 'T->Async<'u>) : Async<NonEmptySeq<_>> = async {
9193
let! ct = Async.CancellationToken
9294
return seq {
9395
use enum = t.GetEnumerator ()
9496
while enum.MoveNext() do
9597
yield Async.RunSynchronously (f enum.Current, cancellationToken = ct) } |> NonEmptySeq<_>.unsafeOfSeq }
9698
#endif
9799

98-
static member inline Sequence (t: NonEmptySeq<'``Applicative<'T>``>) = Sequence.ForInfiniteSequences (t, IsLeftZero.Invoke, NonEmptySeq<_>.ofList) : '``Applicative<NonEmptySeq<'T>>``
100+
static member inline SequenceImpl (t, _, _:obj) = printfn "Using default4"; Sequence.ForInfiniteSequences (t, IsLeftZero.Invoke, NonEmptySeq<_>.ofList)
101+
static member SequenceImpl (t: NonEmptySeq<option<'T>>, _: option<NonEmptySeq<'T>>, _:Sequence) : option<NonEmptySeq<'T>> = printfn "Not Using default4"; Option.Sequence t |> Option.map NonEmptySeq<_>.unsafeOfSeq
102+
103+
static member SequenceImpl (t: NonEmptySeq<Result<'T, 'E>>) : Result<NonEmptySeq<'T>, 'E> = Result.Sequence t |> Result.map NonEmptySeq<_>.unsafeOfSeq
104+
static member SequenceImpl (t: NonEmptySeq<Choice<'T, 'E>>) : Choice<NonEmptySeq<'T>, 'E> = Choice.Sequence t |> Choice.map NonEmptySeq<_>.unsafeOfSeq
105+
static member SequenceImpl (t: NonEmptySeq<list<'T>> , _: list<NonEmptySeq<'T>> , _:Sequence) : list<NonEmptySeq<'T>> = printfn "Not Using default4"; Sequence.ForInfiniteSequences (t, List.isEmpty , NonEmptySeq<_>.ofList)
106+
static member SequenceImpl (t: NonEmptySeq<'T []> ) : NonEmptySeq<'T> [] = Sequence.ForInfiniteSequences (t, Array.isEmpty, NonEmptySeq<_>.ofList)
107+
#if !FABLE_COMPILER
108+
static member SequenceImpl (t: NonEmptySeq<Async<'T>> ) : Async<NonEmptySeq<'T>> = Async.Sequence t |> Async.map NonEmptySeq<_>.unsafeOfSeq
109+
#endif
110+
111+
static member inline Sequence (t: NonEmptySeq<'``Applicative<'T>``>) : '``Applicative<NonEmptySeq<'T>>`` =
112+
let inline call_3 (a: ^a, b: ^b, c: ^c) = ((^a or ^b or ^c) : (static member SequenceImpl : _*_*_ -> _) b, c, a)
113+
let inline call (a: 'a, b: 'b) = call_3 (a, b, Unchecked.defaultof<'R>) : 'R
114+
call (Unchecked.defaultof<Sequence>, t)
115+
116+
117+
118+
99119

100120
/// A type alias for NonEmptySeq<'t>
101121
type neseq<'t> = NonEmptySeq<'t>

tests/FSharpPlus.Tests/Traversals.fs

+2-2
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ module Traversable =
151151
let a = sequence (NonEmptySeq.initInfinite toOptions)
152152
let b = sequence (NonEmptySeq.initInfinite toOptions)
153153
let c = sequence (NonEmptySeq.initInfinite toChoices)
154-
// let d = sequence (NonEmptySeq.initInfinite toLists)
154+
let d = sequence (NonEmptySeq.initInfinite toLists)
155155
let e = sequence (NonEmptySeq.initInfinite toEithers)
156156

157157
CollectionAssert.AreEqual (expectedEffects, SideEffects.get ())
@@ -167,7 +167,7 @@ module Traversable =
167167
Assert.AreEqual (None, a)
168168
Assert.AreEqual (None, b)
169169
Assert.AreEqual (Choice<NonEmptySeq<int>,string>.Choice2Of2 "This is a failure", c)
170-
// Assert.True ((d = []))
170+
Assert.True ((d = []))
171171
Assert.AreEqual (Either<string list,NonEmptySeq<int>>.Left ["This is a failure"], e)
172172

173173

0 commit comments

Comments
 (0)