GarouDan
03/19/2019, 4:34 PMClosure a = { /*...*/ }
Closure b = { /*...*/ }
Closure c = a << b
How can we do that in Kotlin? Merging closures or high order functions?
I’m trying something like:
val a : KotlinSourceSet.() -> Unit = {
dependencies {
implementation(kotlin("stdlib-js"))
}
}
val b: KotlinSourceSet.() -> Unit = {
dependencies {
implementation(project(":common", "jvmApiDefault"))
}
}
where the result that I expect is something like:
val c: KotlinSourceSet.() -> Unit = {
dependencies {
implementation(kotlin("stdlib-js"))
implementation(project(":common", "jvmApiDefault"))
}
}
But how can we properly create the variable c
?streetsofboston
03/19/2019, 4:40 PMstreetsofboston
03/19/2019, 4:44 PMandThen
or compose
function, something like this:
infix fun <A, B, C> ((A) -> B).andThen(g: (B) -> C): (A) -> C = { a: A -> g(this(a)) }
val c = a andThen b
GarouDan
03/19/2019, 4:45 PMval a : KotlinSourceSet.() -> Unit = {
dependencies {
implementation(kotlin("stdlib-js"))
}
}
val b: KotlinSourceSet.() -> Unit = {
dependencies {
implementation(project(":common", "jvmApiDefault"))
}
}
val c: KotlinSourceSet.() -> Unit = {
dependencies {
implementation(kotlin("stdlib-js"))
implementation(project(":common", "jvmApiDefault"))
}
}
I’m needing this for a gradle script of mine.
Where c
is the result that I’m expecting.GarouDan
03/19/2019, 4:52 PMstreetsofboston
03/19/2019, 4:53 PMval c : KotlinSourceSet.() -> Unit= { a(); b() }
Using andThen
would be a generic solution for thisGarouDan
03/19/2019, 5:30 PM