@@ -3,6 +3,7 @@ package arrow.test.laws
3
3
import arrow.Kind
4
4
import arrow.core.Left
5
5
import arrow.core.Right
6
+ import arrow.core.identity
6
7
import arrow.data.Kleisli
7
8
import arrow.free.Free
8
9
import arrow.free.bindingStackSafe
@@ -28,7 +29,8 @@ object MonadLaws {
28
29
Law (" Monad Laws: monad comprehensions binding in other threads" ) { M .monadComprehensionsBindInContext(EQ ) },
29
30
Law (" Monad Laws: stack-safe//unsafe monad comprehensions equivalence" ) { M .equivalentComprehensions(EQ ) },
30
31
Law (" Monad Laws: stack safe" ) { M .stackSafety(5000 , EQ ) },
31
- Law (" Monad Laws: stack safe comprehensions" ) { M .stackSafetyComprehensions(5000 , EQ ) }
32
+ Law (" Monad Laws: stack safe comprehensions" ) { M .stackSafetyComprehensions(5000 , EQ ) },
33
+ Law (" Monad Laws: selectM == select when Selective has a monad instance" ) { M .selectEQSelectM(EQ ) }
32
34
)
33
35
34
36
fun <F > Monad<F>.leftIdentity (EQ : Eq <Kind <F , Int >>): Unit =
@@ -102,6 +104,12 @@ object MonadLaws {
102
104
}.equalUnderTheLaw(just(num + 2 ), EQ )
103
105
}
104
106
107
+ fun <F > Monad<F>.selectEQSelectM (EQ : Eq <Kind <F , Int >>): Unit =
108
+ forAll(Gen .either(Gen .int(), Gen .int())) { either ->
109
+ val f = just< (Int ) -> Int > (::identity)
110
+ just(either).select(f).equalUnderTheLaw(just(either).selectM(f), EQ )
111
+ }
112
+
105
113
fun <F > Monad<F>.monadComprehensionsBindInContext (EQ : Eq <Kind <F , Int >>): Unit =
106
114
forFew(5 , Gen .intSmall()) { num: Int ->
107
115
binding {
0 commit comments