@@ -5,7 +5,9 @@ open System.Runtime.InteropServices
5
5
open System.ComponentModel
6
6
open System.Collections .Generic
7
7
open FSharpPlus
8
+ open FSharpPlus.Extensions
8
9
open FSharpPlus.Control
10
+ open Microsoft.FSharp .Core .CompilerServices
9
11
10
12
/// A type-safe sequence that contains at least one element.
11
13
[<Interface>]
@@ -78,24 +80,42 @@ type NonEmptySeq<'t> =
78
80
79
81
80
82
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))
84
86
85
87
static member inline Traverse ( t : NonEmptySeq < 'T >, f : 'T -> '``Functor < 'U > ``) =
86
88
let mapped = NonEmptySeq<_>. map f t
87
89
Sequence.ForInfiniteSequences ( mapped, IsLeftZero.Invoke, NonEmptySeq<_>. ofList) : '`` Functor<NonEmptySeq<'U>> ``
88
90
89
91
#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 {
91
93
let! ct = Async.CancellationToken
92
94
return seq {
93
95
use enum = t.GetEnumerator ()
94
96
while enum .MoveNext() do
95
97
yield Async.RunSynchronously ( f enum .Current, cancellationToken = ct) } |> NonEmptySeq<_>. unsafeOfSeq }
96
98
#endif
97
99
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
+
99
119
100
120
/// A type alias for NonEmptySeq<'t>
101
121
type neseq < 't > = NonEmptySeq< 't>
0 commit comments