com.swmansion.starknet.extensions.Request.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of starknet Show documentation
Show all versions of starknet Show documentation
Starknet SDK for JVM languages
The newest version!
package com.swmansion.starknet.extensions
import com.swmansion.starknet.provider.Request
import java.util.concurrent.CompletableFuture
internal fun Request.compose(mapping: (value: T) -> Request): Request {
return DependentRequest(this, mapping)
}
internal fun Request.map(mapping: (value: T) -> N): Request {
return MappedRequest(this, mapping)
}
internal class DependentRequest(
private val dependsOn: Request,
private val mapper: (D) -> Request,
) : Request {
override fun send(): T {
return mapper(dependsOn.send()).send()
}
override fun sendAsync(): CompletableFuture {
return dependsOn.sendAsync()
.thenApplyAsync(mapper)
.thenComposeAsync(Request::sendAsync)
}
}
internal class MappedRequest(
private val originalRequest: Request,
private val mapper: (D) -> T,
) : Request {
override fun send(): T {
return mapper(originalRequest.send())
}
override fun sendAsync(): CompletableFuture {
return originalRequest.sendAsync()
.thenApplyAsync(mapper)
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy