Skip to content

Commit 87d272c

Browse files
committed
Add ZipApplicatives, keep Transpose in standby for now
1 parent d28a960 commit 87d272c

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed

src/FSharpPlus/Control/Traversable.fs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,8 @@ type Transpose with
403403
#if !FABLE_COMPILER
404404
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
405405
#endif
406+
407+
(*
406408
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<_>)
407409
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
408410
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
@@ -412,6 +414,7 @@ type Transpose with
412414
#if !FABLE_COMPILER
413415
static member Transpose (t: NonEmptySeq<Async<'t>> , [<Optional>]_output: Async<NonEmptySeq<'t>> , [<Optional>]_impl: Default3) = Async.Parallel t |> Async.map NonEmptySeq.unsafeOfSeq : Async<NonEmptySeq<'t>>
414416
#endif
417+
*)
415418

416419
static member inline Transpose (t: ^a , [<Optional>]_output: 'R, [<Optional>]_impl: Default2) : 'R = Gather.InvokeOnInstance id t
417420
static member inline Transpose (t: ^a , [<Optional>]_output: 'R, [<Optional>]_impl: Default1) : 'R = Transpose.InvokeOnInstance t

src/FSharpPlus/Control/ZipApplicative.fs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ open Microsoft.FSharp.Quotations
1010
open FSharpPlus.Internals
1111
open FSharpPlus.Internals.Prelude
1212
open FSharpPlus
13-
open FSharpPlus.Data
1413

1514

1615
[<System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)>]
@@ -30,8 +29,7 @@ type Pure =
3029
let inline call (mthd: ^M, output: ^R) = ((^M or ^R) : (static member Pure : _*_ -> _) output, mthd)
3130
call (Unchecked.defaultof<Pure>, Unchecked.defaultof<'``ZipApplicative<'T>``>) x
3231

33-
static member Pure (_: seq<'a> , _: Default2 ) = fun x -> Seq.initInfinite (fun _ -> x) : seq<'a>
34-
static member Pure (_: NonEmptySeq<'a> , _: Default2 ) = fun x -> NonEmptySeq.initInfinite (fun _ -> x) : NonEmptySeq<'a>
32+
static member Pure (_: seq<'a> , _: Default2 ) = fun x -> Seq.initInfinite (fun _ -> x) : seq<'a>
3533
static member Pure (_: IEnumerator<'a> , _: Default2 ) = fun x -> Enumerator.upto None (fun _ -> x) : IEnumerator<'a>
3634
static member inline Pure (_: 'R , _: Default1 ) = fun (x: 'T) -> Pure.InvokeOnInstance x : 'R
3735
static member Pure (x: Lazy<'a> , _: Pure) = Return.Return (x, Unchecked.defaultof<Return>) : _ -> Lazy<'a>
@@ -78,8 +76,7 @@ type ZipApply =
7876
#if !FABLE_COMPILER
7977

8078
static member ``<.>`` (struct (f: Lazy<'T->'U> , x: Lazy<'T> ), [<Optional>]_output: Lazy<'U> , [<Optional>]_mthd: ZipApply) = Apply.``<*>`` (struct (f, x), _output, Unchecked.defaultof<Apply>)
81-
static member ``<.>`` (struct (f: seq<_> , x: seq<'T> ), [<Optional>]_output: seq<'U> , [<Optional>]_mthd: ZipApply) = Seq.map2 (<|) f x
82-
static member ``<.>`` (struct (f: NonEmptySeq<_> , x: NonEmptySeq<'T> ), [<Optional>]_output: NonEmptySeq<'U> , [<Optional>]_mthd: ZipApply) = NonEmptySeq.map2 (<|) f x
79+
static member ``<.>`` (struct (f: seq<_> , x: seq<'T> ), [<Optional>]_output: seq<'U> , [<Optional>]_mthd: ZipApply) = Seq.map2 (<|) f x
8380
static member ``<.>`` (struct (f: IEnumerator<_> , x: IEnumerator<'T> ), [<Optional>]_output: IEnumerator<'U> , [<Optional>]_mthd: ZipApply) = Apply.``<*>`` (struct (f, x), _output, Unchecked.defaultof<Apply>)
8481
static member ``<.>`` (struct (f: list<_> , x: list<'T> ), [<Optional>]_output: list<'U> , [<Optional>]_mthd: ZipApply) = List.map2Shortest (<|) f x
8582
static member ``<.>`` (struct (f: _ [] , x: 'T [] ), [<Optional>]_output: 'U [] , [<Optional>]_mthd: ZipApply) = Array.map2Shortest (<|) f x
@@ -136,8 +133,7 @@ type Map2 =
136133
inherit Default1
137134

138135
static member Map2 (f, (x: Lazy<_> , y: Lazy<_> ), _mthd: Map2) = Lift2.Lift2 (f, (x, y), Unchecked.defaultof<Lift2>)
139-
static member Map2 (f, (x: seq<_> , y: seq<_> ), _mthd: Map2) = Seq.map2 f x y
140-
static member Map2 (f, (x: NonEmptySeq<_> , y: NonEmptySeq<_> ), _mthd: Map2) = NonEmptySeq.map2 f x y
136+
static member Map2 (f, (x: seq<_> , y: seq<_> ), _mthd: Map2) = Seq.map2 f x y
141137
static member Map2 (f, (x: IEnumerator<_> , y: IEnumerator<_> ), _mthd: Map2) = Lift2.Lift2 (f, (x, y), Unchecked.defaultof<Lift2>)
142138
static member Map2 (f, (x , y ), _mthd: Map2) = List.map2Shortest f x y
143139
static member Map2 (f, (x: _ [] , y: _ [] ), _mthd: Map2) = Array.map2Shortest f x y
@@ -183,8 +179,7 @@ type Map3 =
183179
inherit Default1
184180

185181
static member Map3 (f, (x: Lazy<_> , y: Lazy<_> , z: Lazy<_> ), _mthd: Map3) = Lift3.Lift3 (f, (x, y, z), Unchecked.defaultof<Lift3>)
186-
static member Map3 (f, (x: seq<_> , y: seq<_> , z: seq<_> ), _mthd: Map3) = Seq.map3 f x y z
187-
static member Map3 (f, (x: NonEmptySeq<_> , y: NonEmptySeq<_> , z: NonEmptySeq<_> ), _mthd: Map3) = NonEmptySeq.map3 f x y z
182+
static member Map3 (f, (x: seq<_> , y: seq<_> , z: seq<_> ), _mthd: Map3) = Seq.map3 f x y z
188183
static member Map3 (f, (x: IEnumerator<_> , y: IEnumerator<_> , z: IEnumerator<_> ), _mthd: Map3) = Lift3.Lift3 (f, (x, y, z), Unchecked.defaultof<Lift3>)
189184
static member Map3 (f, (x , y , z ), _mthd: Map3) = List.map3Shortest f x y z
190185
static member Map3 (f, (x: _ [] , y: _ [] , z: _ [] ), _mthd: Map3) = Array.map3Shortest f x y z
@@ -228,8 +223,7 @@ type Map3 with
228223
type IsZipLeftZero =
229224
inherit Default1
230225

231-
static member IsZipLeftZero (t: ref<seq<_>> , _mthd: IsZipLeftZero) = Seq.isEmpty t.Value
232-
static member IsZipLeftZero (_: ref<NonEmptySeq<_>>, _mthd: IsZipLeftZero) = false
226+
static member IsZipLeftZero (t: ref<seq<_>> , _mthd: IsZipLeftZero) = Seq.isEmpty t.Value
233227
static member IsZipLeftZero (t: ref<list<_>> , _mthd: IsZipLeftZero) = List.isEmpty t.Value
234228
static member IsZipLeftZero (t: ref<array<_>> , _mthd: IsZipLeftZero) = Array.isEmpty t.Value
235229
static member IsZipLeftZero (t: ref<option<_>> , _mthd: IsZipLeftZero) = IsLeftZero.IsLeftZero (t, Unchecked.defaultof<IsLeftZero>)

src/FSharpPlus/Data/NonEmptySeq.fs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,14 @@ type NonEmptySeq<'t> =
6363
static member TryLast (x: NonEmptySeq<'T>, [<Optional>]_impl: TryLast) = Some <| Seq.last x
6464

6565
static member Map (x: NonEmptySeq<_>, f: 'T -> 'U) = NonEmptySeq<_>.map f x : NonEmptySeq<'U>
66+
67+
static member Pure (x: 'T) : NonEmptySeq<'T> = Seq.initInfinite (fun _ -> x) |> NonEmptySeq<_>.unsafeOfSeq
68+
static member (<.>) (f: NonEmptySeq<_>, x: NonEmptySeq<'T>) : NonEmptySeq<'U> = Seq.map2 (<|) f x |> NonEmptySeq<_>.unsafeOfSeq
69+
static member Map2 (f, x: NonEmptySeq<_>, y: NonEmptySeq<_>) = Seq.map2 f x y |> NonEmptySeq<_>.unsafeOfSeq
70+
static member Map3 (f, x: NonEmptySeq<_>, y: NonEmptySeq<_>, z: NonEmptySeq<_>) = Seq.map3 f x y z |> NonEmptySeq<_>.unsafeOfSeq
71+
static member IsZipLeftZero (_: NonEmptySeq<_>) = false
6672

67-
static member Unzip (source: NonEmptySeq<'T * 'U>) = Map.Invoke fst source, Map.Invoke snd source
73+
static member Unzip (source: NonEmptySeq<'T * 'U>) = Map.Invoke fst source, Map.Invoke snd source
6874
static member Zip (x: NonEmptySeq<'T>, y: NonEmptySeq<'U>) = NonEmptySeq<_>.zip x y
6975
static member (>>=) (source: NonEmptySeq<'T>, f: 'T -> NonEmptySeq<'U>) = NonEmptySeq<_>.collect f source : NonEmptySeq<'U>
7076

0 commit comments

Comments
 (0)