Skip to content

Commit bf0ff43

Browse files
committed
Initial implementation
1 parent 812f4eb commit bf0ff43

10 files changed

+103
-90
lines changed

src/FSharpPlus/Builders.fs

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ namespace FSharpPlus
1818
module GenericBuilders =
1919

2020
open FSharpPlus.Operators
21-
open FSharpPlus.Data
2221

2322
// Idiom brackets
2423
type Ii = Ii

src/FSharpPlus/Control/Alternative.fs

-11
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ namespace FSharpPlus.Control
1010

1111
open System.Runtime.InteropServices
1212
open FSharpPlus
13-
open FSharpPlus.Data
1413
open FSharpPlus.Internals
1514

1615

@@ -38,8 +37,6 @@ type Empty with
3837
type Append =
3938
inherit Default1
4039
static member ``<|>`` (x: 'T seq , y , [<Optional>]_mthd: Default2) = Seq.append x y
41-
static member ``<|>`` (x: 'T NonEmptySeq , y , [<Optional>]_mthd: Default2) = NonEmptySeq.append x y
42-
4340
static member inline ``<|>`` (x: '``Alt<'T>`` , y: '``Alt<'T>``, [<Optional>]_mthd: Default1) = (^``Alt<'T>`` : (static member (<|>) : _*_ -> _) x, y) : '``Alt<'T>``
4441
static member inline ``<|>`` (_: ^t when ^t: null and ^t: struct , _, _mthd: Default1) = ()
4542

@@ -114,14 +111,6 @@ type Choice =
114111
res <- Append.Invoke res e.Current
115112
res
116113

117-
static member inline Choice (x: ref<NonEmptySeq<'``Alternative<'T>``>>, _mthd: Choice) =
118-
use e = x.Value.GetEnumerator ()
119-
e.MoveNext() |> ignore
120-
let mutable res = e.Current
121-
while e.MoveNext() && not (IsAltLeftZero.Invoke res) do
122-
res <- Append.Invoke res e.Current
123-
res
124-
125114
static member inline Choice (x: ref<list<'``Alternative<'T>``>>, _mthd: Choice) =
126115
use e = (List.toSeq x.Value ).GetEnumerator ()
127116
let mutable res = Empty.Invoke ()

src/FSharpPlus/Control/Applicative.fs

+4-9
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ open Microsoft.FSharp.Quotations
88

99
open FSharpPlus.Internals
1010
open FSharpPlus
11-
open FSharpPlus.Data
1211

1312

1413
type Apply =
@@ -20,8 +19,7 @@ type Apply =
2019
static member inline ``<*>`` (f: '``Applicative<'T->'U>``, x: '``Applicative<'T>``, [<Optional>]_output: '``Applicative<'U>``, [<Optional>]_mthd:Default1) : '``Applicative<'U>`` = ((^``Applicative<'T->'U>`` or ^``Applicative<'T>`` or ^``Applicative<'U>``) : (static member (<*>) : _*_ -> _) f, x)
2120

2221
static member ``<*>`` (f: Lazy<'T->'U> , x: Lazy<'T> , [<Optional>]_output: Lazy<'U> , [<Optional>]_mthd: Apply) = Lazy.apply f x : Lazy<'U>
23-
static member ``<*>`` (f: seq<_> , x: seq<'T> , [<Optional>]_output: seq<'U> , [<Optional>]_mthd: Apply) = Seq.apply f x : seq<'U>
24-
static member ``<*>`` (f: NonEmptySeq<_> , x: NonEmptySeq<'T> , [<Optional>]_output: NonEmptySeq<'U> , [<Optional>]_mthd: Apply) = NonEmptySeq.apply f x : NonEmptySeq<'U>
22+
static member ``<*>`` (f: seq<_> , x: seq<'T> , [<Optional>]_output: seq<'U> , [<Optional>]_mthd: Apply) = Seq.apply f x : seq<'U>
2523
static member ``<*>`` (f: IEnumerator<_> , x: IEnumerator<'T> , [<Optional>]_output: IEnumerator<'U> , [<Optional>]_mthd: Apply) = Enumerator.map2 id f x : IEnumerator<'U>
2624
static member ``<*>`` (f: list<_> , x: list<'T> , [<Optional>]_output: list<'U> , [<Optional>]_mthd: Apply) = List.apply f x : list<'U>
2725
static member ``<*>`` (f: _ [] , x: 'T [] , [<Optional>]_output: 'U [] , [<Optional>]_mthd: Apply) = Array.apply f x : 'U []
@@ -93,8 +91,7 @@ type Lift2 =
9391
inherit Default1
9492

9593
static member Lift2 (f, (x: Lazy<_> , y: Lazy<_> ), _mthd: Lift2) = Lazy.map2 f x y
96-
static member Lift2 (f, (x: seq<_> , y: seq<_> ), _mthd: Lift2) = Seq.lift2 f x y
97-
static member Lift2 (f, (x: NonEmptySeq<_> , y: NonEmptySeq<_> ), _mthd: Lift2) = NonEmptySeq.lift2 f x y
94+
static member Lift2 (f, (x: seq<_> , y: seq<_> ), _mthd: Lift2) = Seq.lift2 f x y
9895
static member Lift2 (f, (x: IEnumerator<_> , y: IEnumerator<_> ), _mthd: Lift2) = Enumerator.map2 f x y
9996
static member Lift2 (f, (x , y ), _mthd: Lift2) = List.lift2 f x y
10097
static member Lift2 (f, (x , y ), _mthd: Lift2) = Array.lift2 f x y
@@ -140,8 +137,7 @@ type Lift3 =
140137
inherit Default1
141138

142139
static member Lift3 (f, (x: Lazy<_> , y: Lazy<_> , z: Lazy<_> ), _mthd: Lift3) = Lazy.map3 f x y z
143-
static member Lift3 (f, (x: seq<_> , y: seq<_> , z: seq<_> ), _mthd: Lift3) = Seq.lift3 f x y z
144-
static member Lift3 (f, (x: NonEmptySeq<_> , y: NonEmptySeq<_> , z: NonEmptySeq<_> ), _mthd: Lift3) = NonEmptySeq.lift3 f x y z
140+
static member Lift3 (f, (x: seq<_> , y: seq<_> , z: seq<_> ), _mthd: Lift3) = Seq.lift3 f x y z
145141
static member Lift3 (f, (x: IEnumerator<_> , y: IEnumerator<_> , z: IEnumerator<_> ), _mthd: Lift3) = Enumerator.map3 f x y z
146142
static member Lift3 (f, (x , y , z ), _mthd: Lift3) = List.lift3 f x y z
147143
static member Lift3 (f, (x , y , z ), _mthd: Lift3) = Array.lift3 f x y z
@@ -185,8 +181,7 @@ type Lift3 with
185181
type IsLeftZero =
186182
inherit Default1
187183

188-
static member IsLeftZero (t: ref<seq<_>> , _mthd: IsLeftZero) = Seq.isEmpty t.Value
189-
static member IsLeftZero (_: ref<NonEmptySeq<_>>, _mthd: IsLeftZero) = false
184+
static member IsLeftZero (t: ref<seq<_>> , _mthd: IsLeftZero) = Seq.isEmpty t.Value
190185
static member IsLeftZero (t: ref<list<_>> , _mthd: IsLeftZero) = List.isEmpty t.Value
191186
static member IsLeftZero (t: ref<array<_>> , _mthd: IsLeftZero) = Array.isEmpty t.Value
192187
static member IsLeftZero (t: ref<option<_>> , _mthd: IsLeftZero) = Option.isNone t.Value

src/FSharpPlus/Control/Foldable.fs

+3-7
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ open System.Runtime.InteropServices
3434
open System.Text
3535
open System.Collections.Generic
3636
open FSharpPlus
37-
open FSharpPlus.Data
3837
open FSharpPlus.Internals
3938
open FSharpPlus.Internals.Prelude
4039

@@ -231,8 +230,7 @@ type Head =
231230
static member inline Head (x: '``Foldable<'T>``, [<Optional>]_impl: Default2) = Seq.head (ToSeq.Invoke x) : 'T
232231
static member inline Head (x: '``Foldable<'T>``, [<Optional>]_impl: Default1) = (^``Foldable<'T>`` : (member Head : 'T) x)
233232
static member Head (x: 'T option , [<Optional>]_impl: Head ) = x.Value
234-
static member Head (x: 'T [] , [<Optional>]_impl: Head ) = x.[0]
235-
static member Head (x: NonEmptySeq<'T> , [<Optional>]_impl: Head ) = x.First
233+
static member Head (x: 'T [] , [<Optional>]_impl: Head ) = x.[0]
236234
static member Head (x: Id<'T> , [<Optional>]_impl: Head ) = x.getValue
237235
static member Head (x: ResizeArray<'T> , [<Optional>]_impl: Head ) = x.[0]
238236
static member Head (x: string , [<Optional>]_impl: Head ) = x.[0]
@@ -247,8 +245,7 @@ type TryHead =
247245
inherit Default1
248246
static member inline TryHead (x , [<Optional>]_impl: Default1) = Seq.tryHead <| ToSeq.Invoke x
249247
static member TryHead (x: 't list , [<Optional>]_impl: TryHead ) = List.tryHead x
250-
static member TryHead (x: 't [] , [<Optional>]_impl: TryHead ) = Array.tryHead x
251-
static member TryHead (x: NonEmptySeq<'T>,[<Optional>]_impl: TryHead) = Some x.First
248+
static member TryHead (x: 't [] , [<Optional>]_impl: TryHead ) = Array.tryHead x
252249
static member TryHead (x: Id<'T> , [<Optional>]_impl: TryHead ) = Some x.getValue
253250
static member TryHead (x: string , [<Optional>]_impl: TryHead ) = String.tryHead x
254251
static member TryHead (x: StringBuilder, [<Optional>]_impl: TryHead ) = if x.Length = 0 then None else Some (x.ToString().[0])
@@ -263,8 +260,7 @@ type TryLast =
263260
inherit Default1
264261
static member inline TryLast (x , [<Optional>]_impl: Default1) = Seq.tryLast <| ToSeq.Invoke x
265262
static member TryLast (x: 't list , [<Optional>]_impl: TryLast) = List.tryLast x
266-
static member TryLast (x: 't [] , [<Optional>]_impl: TryLast) = Array.tryLast x
267-
static member TryLast (x: NonEmptySeq<'T>, [<Optional>]_impl: TryLast) = Some <| Seq.last x
263+
static member TryLast (x: 't [] , [<Optional>]_impl: TryLast) = Array.tryLast x
268264
static member TryLast (x: Id<'T> , [<Optional>]_impl: TryLast ) = Some x.getValue
269265
static member TryLast (x: string , [<Optional>]_impl: TryLast ) = String.tryLast x
270266
static member TryLast (x: StringBuilder , [<Optional>]_impl: TryLast ) = if x.Length = 0 then None else Some (x.ToString().[x.Length - 1])

src/FSharpPlus/Control/Functor.fs

+3-7
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ open Microsoft.FSharp.Quotations
1111
open FSharpPlus.Internals
1212
open FSharpPlus.Internals.Prelude
1313
open FSharpPlus
14-
open FSharpPlus.Data
1514

1615
#if (!FABLE_COMPILER || FABLE_COMPILER_3) && ! FABLE_COMPILER_4
1716

@@ -125,8 +124,7 @@ type Map with
125124
and '``Applicative<'T->'U>`` : (static member Return : ('T -> 'U) -> '``Applicative<'T->'U>``)
126125
, f: 'T->'U), [<Optional>]_mthd: Default3) = Apply.InvokeOnInstance (Return.InvokeOnInstance f: '``Applicative<'T->'U>``) x : '``Applicative<'U>``
127126

128-
static member Map ((x: seq<_> , f: 'T->'U), _mthd: Default2) = Seq.map f x : seq<'U>
129-
static member Map ((x: NonEmptySeq<_> , f: 'T->'U), _mthd: Default2) = NonEmptySeq.map f x : NonEmptySeq<'U>
127+
static member Map ((x: seq<_> , f: 'T->'U), _mthd: Default2) = Seq.map f x : seq<'U>
130128
static member Map ((x: IEnumerator<_> , f: 'T->'U), _mthd: Default2) = Enumerator.map f x : IEnumerator<'U>
131129
static member Map ((x: IDictionary<_,_> , f: 'T->'U), _mthd: Default2) = Dict.map f x : IDictionary<'Key,'U>
132130
static member Map ((x: IReadOnlyDictionary<_,_>, f: 'T->'U), _mthd: Default2) = IReadOnlyDictionary.mapValues f x : IReadOnlyDictionary<'Key,_>
@@ -183,8 +181,7 @@ type Unzip =
183181

184182
static member Unzip ((source: ResizeArray<'T * 'U> , _output: ResizeArray<'T> * ResizeArray<'U> ) , _mthd: Unzip ) = Map.Invoke fst source, Map.Invoke snd source
185183

186-
static member Unzip ((source: seq<'T * 'U> , _output: seq<'T> * seq<'U> ) , _mthd: Unzip ) = Map.Invoke fst source, Map.Invoke snd source
187-
static member Unzip ((source: NonEmptySeq<'T * 'U> , _output: NonEmptySeq<'T> * NonEmptySeq<'U> ) , _mthd: Unzip ) = Map.Invoke fst source, Map.Invoke snd source
184+
static member Unzip ((source: seq<'T * 'U> , _output: seq<'T> * seq<'U> ) , _mthd: Unzip ) = Map.Invoke fst source, Map.Invoke snd source
188185

189186
static member Unzip ((source: IEnumerator<'T * 'U> , _output: IEnumerator<'T> * ResizeArray<'U> ) , _mthd: Unzip ) = Map.Invoke fst source, Map.Invoke snd source
190187
static member Unzip ((source: IDictionary<'Key, 'T * 'U> , _output: IDictionary<_,'T> * IDictionary<_,'U> ) , _mthd: Unzip ) = Dict.unzip source
@@ -204,8 +201,7 @@ type Unzip =
204201
type Zip =
205202
inherit Default1
206203
static member Zip ((x: IEnumerator<'T> , y: IEnumerator<'U> , _output: IEnumerator<'T*'U> ), _mthd: Zip) = Enumerator.zip x y
207-
static member Zip ((x: seq<'T> , y: seq<'U> , _output: seq<'T*'U> ), _mthd: Zip) = Seq.zip x y
208-
static member Zip ((x: NonEmptySeq<'T> , y: NonEmptySeq<'U> , _output: NonEmptySeq<'T*'U> ), _mthd: Zip) = NonEmptySeq.zip x y
204+
static member Zip ((x: seq<'T> , y: seq<'U> , _output: seq<'T*'U> ), _mthd: Zip) = Seq.zip x y
209205
static member Zip ((x: IDictionary<'K, 'T> , y: IDictionary<'K,'U> , _output: IDictionary<'K,'T*'U> ), _mthd: Zip) = Dict.zip x y
210206
static member Zip ((x: IReadOnlyDictionary<'K, 'T>, y: IReadOnlyDictionary<'K,'U>, _output: IReadOnlyDictionary<'K,'T*'U>), _mthd: Zip) = IReadOnlyDictionary.zip x y
211207
static member Zip ((x: Dictionary<'K, 'T> , y: Dictionary<'K,'U> , _output: Dictionary<'K,'T*'U> ), _mthd: Zip) = Dict.zip x y :?> Dictionary<'K,'T*'U>

src/FSharpPlus/Control/Monad.fs

-10
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ open System.Threading.Tasks
88
open Microsoft.FSharp.Quotations
99

1010
open FSharpPlus
11-
open FSharpPlus.Data
1211
open FSharpPlus.Internals
1312
open FSharpPlus.Internals.Prelude
1413

@@ -60,8 +59,6 @@ type Bind =
6059

6160
static member (>>=) (source: ResizeArray<'T>, f: 'T -> ResizeArray<'U>) = ResizeArray (Seq.bind (f >> seq<_>) source) : ResizeArray<'U>
6261

63-
static member (>>=) (source: NonEmptySeq<'T>, f: 'T -> NonEmptySeq<'U>) = NonEmptySeq.collect f source : NonEmptySeq<'U>
64-
6562
#if !FABLE_COMPILER || FABLE_COMPILER_3
6663
static member inline Invoke (source: '``Monad<'T>``) (binder: 'T -> '``Monad<'U>``) : '``Monad<'U>`` =
6764
let inline call (_mthd: 'M, input: 'I, _output: 'R, f) = ((^M or ^I or ^R) : (static member (>>=) : _*_ -> _) input, f)
@@ -115,8 +112,6 @@ type Join =
115112
dct
116113

117114
static member Join (x: ResizeArray<ResizeArray<'T>> , [<Optional>]_output: ResizeArray<'T> , [<Optional>]_mthd: Join) = ResizeArray (Seq.bind seq<_> x) : ResizeArray<'T>
118-
119-
static member Join (x: NonEmptySeq<NonEmptySeq<'T>> , [<Optional>]_output: NonEmptySeq<'T> , [<Optional>]_mthd: Join) = NonEmptySeq.concat x : NonEmptySeq<'T>
120115

121116
static member inline Invoke (source: '``Monad<Monad<'T>>``) : '``Monad<'T>`` =
122117
let inline call (mthd: 'M, input: 'I, output: 'R) = ((^M or ^I or ^R) : (static member Join : _*_*_ -> _) input, output, mthd)
@@ -137,7 +132,6 @@ type Return =
137132

138133

139134
static member Return (_: seq<'a> , _: Default2) = fun x -> Seq.singleton x : seq<'a>
140-
static member Return (_: NonEmptySeq<'a>, _: Default2) = fun x -> NonEmptySeq.singleton x : NonEmptySeq<'a>
141135
static member Return (_: IEnumerator<'a>, _: Default2) = fun x -> Enumerator.upto None (fun _ -> x) : IEnumerator<'a>
142136
static member inline Return (_: 'R , _: Default1) = fun (x: 'T) -> Return.InvokeOnInstance x : 'R
143137
static member Return (_: Lazy<'a> , _: Return ) = fun x -> Lazy<_>.CreateFromValue x : Lazy<'a>
@@ -179,7 +173,6 @@ type Delay =
179173
static member inline Delay (_mthd: Default1, _: unit-> ^t when ^t : null and ^t : struct , _ ) = ()
180174

181175
static member Delay (_mthd: Default2, x: unit-> _ , _ ) = Seq.delay x : seq<'T>
182-
static member Delay (_mthd: Default2, x: unit-> _ , _ ) = NonEmptySeq.delay x : NonEmptySeq<'T>
183176
static member Delay (_mthd: Default2, x: unit-> 'R -> _ , _ ) = (fun s -> x () s): 'R -> _
184177
static member Delay (_mthd: Delay , x: unit-> _ , _ ) = async.Delay x : Async<'T>
185178
static member Delay (_mthd: Delay , x: unit-> Task<_> , _ ) = x () : Task<'T>
@@ -239,7 +232,6 @@ type TryWith =
239232
static member inline TryWith (_: unit -> ^t when ^t: null and ^t: struct, _ : exn -> 't , _: Default1, _) = ()
240233

241234
static member TryWith (computation: unit -> seq<_> , catchHandler: exn -> seq<_> , _: Default2, _) = seq (try (Seq.toArray (computation ())) with e -> Seq.toArray (catchHandler e))
242-
static member TryWith (computation: unit -> NonEmptySeq<_>, catchHandler: exn -> NonEmptySeq<_>, _: Default2, _) = seq (try (Seq.toArray (computation ())) with e -> Seq.toArray (catchHandler e)) |> NonEmptySeq.unsafeOfSeq
243235
static member TryWith (computation: unit -> 'R -> _ , catchHandler: exn -> 'R -> _ , _: Default2, _) = (fun s -> try (computation ()) s with e -> catchHandler e s) : 'R ->_
244236
static member TryWith (computation: unit -> Async<_> , catchHandler: exn -> Async<_> , _: TryWith , _) = async.TryWith ((computation ()), catchHandler)
245237
#if !FABLE_COMPILER
@@ -264,7 +256,6 @@ type TryFinally =
264256
inherit Default1
265257

266258
static member TryFinally ((computation: unit -> seq<_> , compensation: unit -> unit), _: Default2, _, _) = seq { try for e in computation () do yield e finally compensation () }
267-
static member TryFinally ((computation: unit -> NonEmptySeq<_>, compensation: unit -> unit), _: Default2, _, _) = seq { try for e in computation () do yield e finally compensation () } |> NonEmptySeq.unsafeOfSeq
268259

269260
[<CompilerMessage(MessageTryFinally, CodeTryFinally, IsError = true)>]
270261
static member TryFinally ((_: unit -> 'R -> _ , _: unit -> unit), _: Default2 , _, _defaults: False) = raise Internals.Errors.exnUnreachable
@@ -306,7 +297,6 @@ type Using =
306297
inherit Default1
307298

308299
static member Using (resource: 'T when 'T :> IDisposable, body: 'T -> seq<'U> , _: Using) = seq { try for e in body resource do yield e finally if not (isNull (box resource)) then resource.Dispose () } : seq<'U>
309-
static member Using (resource: 'T when 'T :> IDisposable, body: 'T -> NonEmptySeq<'U>, _: Using) = seq { try for e in body resource do yield e finally if not (isNull (box resource)) then resource.Dispose () } |> NonEmptySeq.unsafeOfSeq : NonEmptySeq<'U>
310300
static member Using (resource: 'T when 'T :> IDisposable, body: 'T -> 'R -> 'U , _: Using ) = (fun s -> try body resource s finally if not (isNull (box resource)) then resource.Dispose ()) : 'R->'U
311301
static member Using (resource: 'T when 'T :> IDisposable, body: 'T -> Async<'U>, _: Using ) = async.Using (resource, body)
312302
#if !FABLE_COMPILER

src/FSharpPlus/Control/Monoid.fs

-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ open System.Runtime.InteropServices
88
open Microsoft.FSharp.Quotations
99
open System.Threading.Tasks
1010
open FSharpPlus
11-
open FSharpPlus.Data
1211
open FSharpPlus.Internals
1312
open FSharpPlus.Internals.Prelude
1413

@@ -156,7 +155,6 @@ type Plus with
156155
#if !FABLE_COMPILER
157156
static member inline ``+`` (x: IReadOnlyDictionary<'K,'V>, y: IReadOnlyDictionary<'K,'V>, [<Optional>]_mthd: Default3) = IReadOnlyDictionary.unionWith Plus.Invoke x y
158157
#endif
159-
static member inline ``+`` (x: _ NonEmptySeq , y: _ NonEmptySeq , [<Optional>]_mthd: Default3) = NonEmptySeq.append x y
160158

161159

162160

0 commit comments

Comments
 (0)