herlevsen
01/22/2019, 11:29 PMstreetsofboston
01/22/2019, 11:53 PMbinding
lambda has a this
receiver that probably has a type (don’t know which type) with an instance method fun Either<L,B>.bind(): B
simon.vergauwen
01/22/2019, 11:56 PMMonadContinuation
streetsofboston
01/22/2019, 11:59 PMherlevsen
01/23/2019, 12:17 AMstreetsofboston
01/23/2019, 1:54 AMEither
) available only in the the context of another type (MonadContinuation
).
E.g.
class MonadContinuation<L,R> {
...
fun Either<L,R>.bind(): R = ... // The function `bind` has two receivers: 1. An Either and 2. this MonadContinuation
}
fun <L,R> binding(block: MonadContinuation<L,R>.() -> R) : R = MonadContinuation().block()
...
binding<Error, Int> { // 'this' is an instance of MonadContinuation here
...
val result = Either.Some(5).bind() // The function `bind` is called on the Either in the context of 'this'.
...
result
}
simon.vergauwen
01/23/2019, 8:24 AMsimon.vergauwen
01/23/2019, 8:24 AMwith(TextView()) {
id = R.id.text_view
text = "Hello World!"
}
simon.vergauwen
01/23/2019, 8:26 AMwith
enables a lambda in the form T.() -> R
. Which basically is an anonymous extension function for T
, here View
. So any (instance) method available for View
is now enabled in the with
block.simon.vergauwen
01/23/2019, 8:27 AMbinding
. It takes an anonymous extension function or extension function with receiver of type MonadContinuation
. And monad continuation has bind
methods, so within binding
you can use this method.herlevsen
01/23/2019, 10:12 AMherlevsen
01/23/2019, 10:13 AMsimon.vergauwen
01/23/2019, 10:13 AMsimon.vergauwen
01/23/2019, 10:13 AMraulraja
01/23/2019, 11:06 AMbind
is available for either
because either is also a Kind<ForEither, A>
and bind
is available to all Kind<F, A>
raulraja
01/23/2019, 11:06 AMKind<F, A>
you just made you first higer kinded typeraulraja
01/23/2019, 11:06 AMraulraja
01/23/2019, 11:07 AMbind
is one of themraulraja
01/23/2019, 11:07 AMraulraja
01/23/2019, 11:07 AMcomponent1
raulraja
01/23/2019, 11:08 AMval (one) = 1.right()
raulraja
01/23/2019, 11:08 AMraulraja
01/23/2019, 11:08 AMraulraja
01/23/2019, 11:08 AMraulraja
01/23/2019, 11:09 AM