Edgar Avuzi
12/22/2024, 7:45 AM.let are redundant here (because there is no null to handle using ?.let ). Still this disadvantage does not outweight. IMOokarm
12/22/2024, 8:47 AM.let(::File) and .let(::println)Edgar Avuzi
12/22/2024, 9:12 AMArjan van Wieringen
12/23/2024, 7:39 AMCLOVIS
12/23/2024, 8:50 AM.let(::File) is fine to me, but it starts getting smelly as soon as a .let is inside another .let . To me that's a sign that the outer one should be a regular function call, not chained.Klitos Kyriacou
12/23/2024, 9:58 AM.let is not in the same column position as the previous `.let`s, due to the braces.Klitos Kyriacou
12/23/2024, 10:12 AMURI into a File. If the URI points to an entry in a jar file, then it's not a File and you'll get an exception if you try to read from it like that. You can instead read it directly using getResourceAsStream() and turning it into a Reader. You should then ensure it gets closed after reading, by using the use function. Also, there are some ways to simplify the code, for example using sumOf. So your initial code can be written like this:
({}.javaClass.classLoader.getResourceAsStream("input3.txt") ?: return)
.reader()
.use { it.readText() }
.let { regex.findAll(it) }
.map { it.destructured }
.sumOf { (a, b) -> a.toInt() * b.toInt() }
.let { println(it) }Edgar Avuzi
12/24/2024, 2:39 AM