michaelrocks
04/08/2016, 1:33 PMmichaelrocks
04/08/2016, 1:34 PMinline fun <T : Any> given(condition: Boolean, body: () -> T): T? =
if (condition) body() else null
kirillrakhman
04/08/2016, 1:36 PMmichaelrocks
04/08/2016, 1:38 PMgiven(changes.hasValue()) { changes.value }
uhe
04/08/2016, 1:45 PMcondition: (T) -> Boolean
if you want to use it
kirillrakhman
04/08/2016, 1:45 PMkirillrakhman
04/08/2016, 1:46 PMit
in thereuhe
04/08/2016, 1:46 PMuhe
04/08/2016, 1:46 PMkirillrakhman
04/08/2016, 1:47 PMkirillrakhman
04/08/2016, 1:47 PMuhe
04/08/2016, 1:49 PMkirillrakhman
04/08/2016, 1:50 PMcedric
04/08/2016, 1:52 PMPreconditions.kt
, e.g. requireNotNull(project.version, { "version mandatory on project ${project.name}" })
kirillrakhman
04/08/2016, 1:53 PMkirillrakhman
04/08/2016, 1:53 PMnull
insteadcedric
04/08/2016, 1:53 PMmplatvoet
04/08/2016, 2:01 PMorangy
ylemoigne
04/10/2016, 9:03 PMrafal
04/12/2016, 10:19 AMyole
04/12/2016, 10:55 AMrafal
04/12/2016, 10:56 AMrafal
04/12/2016, 10:56 AMkirillrakhman
04/12/2016, 10:56 AMrafal
04/12/2016, 11:09 AMmichaelsims
04/13/2016, 12:04 AMuse
. Suppose I wanted to simply copy an InputStream to an OutputStream and make sure both streams are closed. Would the following be considered idiomatic or is there a cleaner/simpler way?michaelsims
04/13/2016, 12:04 AMresponse.bodyStream.use { input ->
buffer.use { output ->
input.copyTo(output)
}
}
michaelsims
04/13/2016, 12:05 AMresponse.bodyStream
is an InputStream
and buffer
is an OutputStream
, naturally)hastebrot
04/13/2016, 8:04 AMuse()
.