Move binding type declarations to lefthand of callsite
This commit is contained in:
parent
f7c9f605f1
commit
d8ea6e1c04
@ -187,7 +187,7 @@ suspend fun failsIn5ms(): Result<Int, DomainErrorA> { ... }
|
||||
suspend fun failsIn1ms(): Result<Int, DomainErrorB> { ... }
|
||||
|
||||
runBlocking {
|
||||
val result = binding<Int, BindingError> {
|
||||
val result: Result<Int, BindingError> = binding {
|
||||
val x = async { failsIn5ms().bind() }
|
||||
val y = async { failsIn1ms().bind() }
|
||||
x.await() + y.await()
|
||||
|
@ -16,7 +16,7 @@ class BindingBenchmark {
|
||||
|
||||
@Benchmark
|
||||
fun bindingSuccess(blackhole: Blackhole) {
|
||||
val result = binding<Int, Error> {
|
||||
val result: Result<Int, Error> = binding {
|
||||
val x = provideX().bind()
|
||||
val y = provideY().bind()
|
||||
x + y
|
||||
@ -27,7 +27,7 @@ class BindingBenchmark {
|
||||
|
||||
@Benchmark
|
||||
fun bindingFailure(blackhole: Blackhole) {
|
||||
val result = binding<Int, Error> {
|
||||
val result: Result<Int, Error> = binding {
|
||||
val x = provideX().bind()
|
||||
val z = provideZ().bind()
|
||||
x + z
|
||||
|
@ -42,29 +42,25 @@ class SuspendBindingBenchmark {
|
||||
|
||||
private val time = 100L
|
||||
|
||||
private fun nonSuspend() = binding<Int, Error> {
|
||||
private fun nonSuspend(): Result<Int, Error> = binding {
|
||||
val x = provideXBlocking().bind()
|
||||
val y = provideYBlocking().bind()
|
||||
x + y
|
||||
}
|
||||
|
||||
private suspend fun withSuspend(): Result<Int, Error> {
|
||||
return coroutineBinding {
|
||||
private suspend fun withSuspend(): Result<Int, Error> = coroutineBinding {
|
||||
val x = provideX().bind()
|
||||
val y = provideY().bind()
|
||||
x + y
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun withAsyncSuspend(): Result<Int, Error> {
|
||||
return coroutineScope {
|
||||
private suspend fun withAsyncSuspend(): Result<Int, Error> = coroutineScope {
|
||||
coroutineBinding {
|
||||
val x = async { provideX().bind() }
|
||||
val y = async { provideY().bind() }
|
||||
x.await() + y.await()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun provideXBlocking(): Result<Int, Error> {
|
||||
Thread.sleep(time)
|
||||
|
@ -28,7 +28,7 @@ class SuspendableBindingTest {
|
||||
return Ok(2)
|
||||
}
|
||||
|
||||
val result = binding<Int, BindingError> {
|
||||
val result: Result<Int, BindingError> = binding {
|
||||
val x = provideX().bind()
|
||||
val y = provideY().bind()
|
||||
x + y
|
||||
@ -52,7 +52,7 @@ class SuspendableBindingTest {
|
||||
return Ok(x + 2)
|
||||
}
|
||||
|
||||
val result = binding<Int, BindingError> {
|
||||
val result: Result<Int, BindingError> = binding {
|
||||
val x = provideX().bind()
|
||||
val y = provideY(x.toInt()).bind()
|
||||
y
|
||||
@ -81,7 +81,7 @@ class SuspendableBindingTest {
|
||||
return Ok(2)
|
||||
}
|
||||
|
||||
val result = binding<Int, BindingError> {
|
||||
val result: Result<Int, BindingError> = binding {
|
||||
val x = provideX().bind()
|
||||
val y = provideY().bind()
|
||||
val z = provideZ().bind()
|
||||
@ -118,7 +118,7 @@ class SuspendableBindingTest {
|
||||
return Err(BindingError)
|
||||
}
|
||||
|
||||
val result = binding<Int, BindingError> {
|
||||
val result: Result<Int, BindingError> = binding {
|
||||
val x = provideX().bind()
|
||||
val y = provideY().bind()
|
||||
val z = provideZ().bind()
|
||||
@ -152,7 +152,7 @@ class SuspendableBindingTest {
|
||||
return Ok(2)
|
||||
}
|
||||
|
||||
val result = binding<Int, BindingError> {
|
||||
val result: Result<Int, BindingError> = binding {
|
||||
val x = provideX().bind()
|
||||
val y = provideY().bind()
|
||||
val z = provideZ().bind()
|
||||
|
@ -34,7 +34,7 @@ class AsyncSuspendableBindingTest {
|
||||
return Ok(2)
|
||||
}
|
||||
|
||||
val result = binding<Int, BindingError> {
|
||||
val result: Result<Int, BindingError> = binding {
|
||||
val x = async { provideX().bind() }
|
||||
val y = async { provideY().bind() }
|
||||
x.await() + y.await()
|
||||
@ -63,7 +63,7 @@ class AsyncSuspendableBindingTest {
|
||||
return Err(BindingError.BindingErrorB)
|
||||
}
|
||||
|
||||
val result = binding<Int, BindingError> {
|
||||
val result: Result<Int, BindingError> = binding {
|
||||
val x = async { provideX().bind() }
|
||||
val y = async { provideY().bind() }
|
||||
val z = async { provideZ().bind() }
|
||||
@ -96,7 +96,7 @@ class AsyncSuspendableBindingTest {
|
||||
val dispatcherA = StandardTestDispatcher(testScheduler)
|
||||
val dispatcherB = StandardTestDispatcher(testScheduler)
|
||||
|
||||
val result = binding<Int, BindingError> {
|
||||
val result: Result<Int, BindingError> = binding {
|
||||
val x = async(dispatcherA) { provideX().bind() }
|
||||
val y = async(dispatcherB) { provideY().bind() }
|
||||
|
||||
@ -143,7 +143,7 @@ class AsyncSuspendableBindingTest {
|
||||
val dispatcherB = StandardTestDispatcher(testScheduler)
|
||||
val dispatcherC = StandardTestDispatcher(testScheduler)
|
||||
|
||||
val result = binding<Unit, BindingError> {
|
||||
val result: Result<Unit, BindingError> = binding {
|
||||
launch(dispatcherA) { provideX().bind() }
|
||||
|
||||
testScheduler.advanceTimeBy(20)
|
||||
|
@ -66,7 +66,7 @@ class BindingTest {
|
||||
fun provideY(): Result<String, BindingError> = Err(BindingError)
|
||||
fun provideZ(): Result<Int, BindingError> = Ok(2)
|
||||
|
||||
val result = binding<Int, BindingError> {
|
||||
val result: Result<Int, BindingError> = binding {
|
||||
val x = provideX().bind()
|
||||
val y = provideY().bind()
|
||||
val z = provideZ().bind()
|
||||
|
Loading…
Reference in New Issue
Block a user