applyIf

inline fun <T> T.applyIf(condition: Boolean, block: T.() -> Unit): T

Runs block on this receiver when condition is true and returns the receiver.

A conditional apply. The receiver is returned unchanged when condition is false.

val request = HttpRequestBuilder()
.applyIf(compress) { header("Content-Encoding", "gzip") }

Return

the receiver, for chaining.

Parameters

condition

whether to run block.

block

configuration to apply to the receiver.