Tristan Hamilton
12/01/2020, 4:46 PMinline
the lambda. Any reasons why you may want to write it this way over a receiver?
fun myScopedIntFunction(block: MyCustomIntFunctionScope): Int {
return block.receive()
}
fun interface MyCustomIntFunctionScope {
fun receive(): Int
fun Int.plusThree(): Int {
return this + 3
}
}
fun main(){
myScopedIntFunction {
1.plusThree() //won't compile
}
object: MyCustomIntFunctionScope {
override fun receive(): Int {
return 1.plusThree()
}
}.receive() //works
}
raulraja
12/02/2020, 9:49 AMTristan Hamilton
12/02/2020, 4:53 PM{ EitherEffect { it } }
what exactly is happening here?raulraja
12/02/2020, 5:54 PMit
is a delimited scope in which shift
relied for the either impl but is deferred all the way to the end so it can support multiple strategies, suspended, restricted, multishot etc.it
implements control
from https://gist.github.com/raulraja/e732bdaace04426d3be4380b7760a8c0#file-prelude-kt-L56Reset.suspended { Right(f(EitherEffect { this /* this is DelimitedScope<Either<E, A>> */ }) }
is another way to implement the computation explicitlyjulian
12/16/2020, 6:36 AMI think it's a great technique to derive other methods polymorphic in the fun interface.Can you explain this a bit more, or point to an example in the gist you shared where this is done? I don't understand what it means to "derive other methods polymorphic in the fun interface". Thanks!
raulraja
12/16/2020, 9:22 AMfun interface
takes a single abstract method you can still define the rest of the interface methods as extensions and delegate to the polymorphic implementation to avoid implementing it concretely. It’s just a nice thing but most likely we won’t have that fun interface for Functor in Arrow. In whatever case you can see there how the fun interface matches the Either::map function which is the only one the data type needs to implement in this case.julian
12/16/2020, 3:52 PMfproduct
! Thanks for explaining @raulraja!