Skip to content

Commit 98dd2f5

Browse files
committed
+ Test
1 parent 204b4ba commit 98dd2f5

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

tests/FSharpPlus.Tests/General.fs

+19
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,13 @@ type WrappedSeqE<'s> = WrappedSeqE of 's seq with
220220
static member Reduce (WrappedSeqE x, reduction) = SideEffects.add "Using WrappedSeqE's Reduce"; Seq.reduce reduction x
221221
static member ToSeq (WrappedSeqE x) = SideEffects.add "Using WrappedSeqE's ToSeq"; x
222222

223+
type WrappedSeqF<'s> = WrappedSeqF of 's seq with
224+
interface Collections.Generic.IEnumerable<'s> with member x.GetEnumerator () = (let (WrappedSeqF x) = x in x).GetEnumerator ()
225+
interface Collections.IEnumerable with member x.GetEnumerator () = (let (WrappedSeqF x) = x in x).GetEnumerator () :> Collections.IEnumerator
226+
static member Return x = SideEffects.add "Using WrappedSeqF's Return"; WrappedSeqF (Seq.singleton x)
227+
static member (<*>) (WrappedSeqF f, WrappedSeqF x) = SideEffects.add "Using WrappedSeqF's Apply"; WrappedSeqF (f <*> x)
228+
static member ToList (WrappedSeqF x) = Seq.toList x
229+
223230
type TestNonEmptyCollection<'a> = private { Singleton: 'a } with
224231
interface NonEmptySeq<'a> with
225232
member this.First =
@@ -1205,6 +1212,18 @@ module Applicative =
12051212
Assert.AreEqual ([4;5;6], res456)
12061213
Assert.AreEqual (toList (run res9n5), toList (run' res9n5'))
12071214

1215+
// WrappedSeqC is Monad. Monads are Applicatives => (<*>) should work
1216+
let (res3: WrappedSeqC<_>) = WrappedSeqC [(+) 1] <*> WrappedSeqC [2]
1217+
CollectionAssert.AreEqual (WrappedSeqC [3], res3)
1218+
1219+
// Check user defined types implementing IEnumerable don't default to seq<_>
1220+
let res4 = WrappedSeqF [(+) 1] <*> WrappedSeqF [3]
1221+
Assert.IsInstanceOf<Option<WrappedSeqF<int>>> (Some res4)
1222+
CollectionAssert.AreEqual (WrappedSeqF [4], res4)
1223+
let res5 = WrappedSeqF [(+)] <*> WrappedSeqF [3] <*> WrappedSeqF [2]
1224+
Assert.IsInstanceOf<Option<WrappedSeqF<int>>> (Some res5)
1225+
CollectionAssert.AreEqual (WrappedSeqF [5], res5)
1226+
12081227
let testLift2 () =
12091228
let expectedEffects = ["Using WrappedSeqD's Return"; "Using WrappedSeqD's Apply"; "Using WrappedSeqD's Apply"]
12101229
SideEffects.reset ()

0 commit comments

Comments
 (0)