From ac46e9bf5c71bb92cd56eb1b401b1da95d517307 Mon Sep 17 00:00:00 2001
From: gusty <1261319+gusty@users.noreply.github.com>
Date: Sat, 25 Nov 2023 12:35:32 +0100
Subject: [PATCH 01/12] + Failing test
---
tests/FSharpPlus.Tests/General.fs | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/tests/FSharpPlus.Tests/General.fs b/tests/FSharpPlus.Tests/General.fs
index ee15954da..f6f9b0a3e 100644
--- a/tests/FSharpPlus.Tests/General.fs
+++ b/tests/FSharpPlus.Tests/General.fs
@@ -220,6 +220,13 @@ type WrappedSeqE<'s> = WrappedSeqE of 's seq with
static member Reduce (WrappedSeqE x, reduction) = SideEffects.add "Using WrappedSeqE's Reduce"; Seq.reduce reduction x
static member ToSeq (WrappedSeqE x) = SideEffects.add "Using WrappedSeqE's ToSeq"; x
+type WrappedSeqF<'s> = WrappedSeqF of 's seq with
+ interface Collections.Generic.IEnumerable<'s> with member x.GetEnumerator () = (let (WrappedSeqF x) = x in x).GetEnumerator ()
+ interface Collections.IEnumerable with member x.GetEnumerator () = (let (WrappedSeqF x) = x in x).GetEnumerator () :> Collections.IEnumerator
+ static member Return x = SideEffects.add "Using WrappedSeqF's Return"; WrappedSeqF (Seq.singleton x)
+ static member (<*>) (WrappedSeqF f, WrappedSeqF x) = SideEffects.add "Using WrappedSeqF's Apply"; WrappedSeqF (f <*> x)
+ static member ToList (WrappedSeqF x) = Seq.toList x
+
type TestNonEmptyCollection<'a> = private { Singleton: 'a } with
interface NonEmptySeq<'a> with
member this.First =
@@ -1205,6 +1212,18 @@ module Applicative =
Assert.AreEqual ([4;5;6], res456)
Assert.AreEqual (toList (run res9n5), toList (run' res9n5'))
+ // WrappedSeqC is Monad. Monads are Applicatives => (<*>) should work
+ let (res3: WrappedSeqC<_>) = WrappedSeqC [(+) 1] <*> WrappedSeqC [2]
+ CollectionAssert.AreEqual (WrappedSeqC [3], res3)
+
+ // Check user defined types implementing IEnumerable don't default to seq<_>
+ let res4 = WrappedSeqF [(+) 1] <*> WrappedSeqF [3]
+ Assert.IsInstanceOf