i’m trying to use this library to extract a tar fi...
# getting-started
m
i’m trying to use this library to extract a tar file https://github.com/kamranzafar/jtar but i’m having trouble converting the example to kotlin since assignment doesn’t work in while conditions. how can i accomplish the same thing in kotlin, or does anyone have a suggestion for a kotlin-first library for this task?
a
Well I think you could assign using
also
Eg
while(origin.read(data).also{ count = it } != -1)
t
use this idiom: object Tis{ fun read(): Int = Random.nextInt(-1, 10) } fun main() { while(true){ val count = Tis.read().takeIf { it != -1 } ?: break println("count: $count") } println("ready") }
n
you can also do
read().also { count = it } != -1
in case its more readable than restructuring the code
222 Views