pakoito
03/08/2019, 1:27 AM-- | One can easily implement a monadic 'selectM' that satisfies the laws,
-- hence any 'Monad' is 'Selective'.
selectM :: Monad f => f (Either a b) -> f (a -> b) -> f b
selectM x y = x >>= \e -> case e of Left a -> ($a) <$> y -- execute y
Right b -> pure b -- skip y
pakoito
03/08/2019, 1:27 AMpakoito
03/08/2019, 1:27 AMRichard Gibson
03/08/2019, 1:28 AMRichard Gibson
03/08/2019, 1:29 AMpakoito
03/08/2019, 1:29 AMflatMap { it.mapLeft { a -> fs.map { ff -> ff(a) } } }
Richard Gibson
03/08/2019, 1:30 AMpakoito
03/08/2019, 1:30 AMpakoito
03/08/2019, 1:31 AMRichard Gibson
03/08/2019, 1:34 AMpakoito
03/08/2019, 1:38 AMflatMap { it.fold({ a -> f.map { ff -> ff(a) } }, { b -> just(b) }) }
pakoito
03/08/2019, 1:38 AMpakoito
03/08/2019, 1:40 AMRichard Gibson
03/08/2019, 9:49 AM@extension
interface MonadSelective<F>: Selective<F> {
fun M(): Monad<F>
override fun <A, B> Kind<F, A>.ap(ff: Kind<F, (A) -> B>): Kind<F, B> =
M().run { this@ap.ap(ff) }
override fun <A> just(a: A): Kind<F, A> = M().just(a)
override fun <A, B> Kind<F, Either<A, B>>.select(f: Kind<F, (A) -> B>): Kind<F, B> =
M().run { this@select.selectM(f) }
}
raulraja
03/08/2019, 9:56 AMraulraja
03/08/2019, 9:57 AMRichard Gibson
03/08/2019, 10:02 AMraulraja
03/08/2019, 10:51 AMraulraja
03/08/2019, 10:51 AMpakoito
03/08/2019, 11:24 AMpakoito
03/08/2019, 11:24 AMraulraja
03/08/2019, 11:41 AMraulraja
03/08/2019, 11:42 AMraulraja
03/08/2019, 11:42 AMpakoito
03/08/2019, 11:43 AMSo not the other way around, not all selective are monads?haven't found a case yet buuut maybe it's in the paper?
pakoito
03/08/2019, 11:44 AMIdeally if all selectives are also Monadit's the same as the relationship between functor and applicative. If you have an applicative, it has a default override for functor in terms of itself
pakoito
03/08/2019, 11:44 AMpakoito
03/08/2019, 11:44 AMstojan
03/08/2019, 12:09 PMcreateTestCase
function (used by UnitSpec
in arrow) now expects a test: suspend io.kotlintest.TestContext.() -> kotlin.Unit
(previously it wasn't suspended)
any ideas how to solve this?pakoito
03/08/2019, 12:14 PM