louiscad
04/15/2021, 8:35 PMedrd
04/16/2021, 3:37 PMSequence
were annotated with @Terminal
or something like that to allow easier creation of automated checks for expressions that don't do anything because the developer forgot to call a terminal operation. Me and my team just spent ~2 hours trying to figure out why our code wasn't working after replacing a forEach
call with map
. A detekt rule / IntelliJ inspection would help a lot in this case.Tomasz Krakowiak
04/19/2021, 3:19 PMCloseable
interface and use extension is not in the common stdlib?
Thread in Slack Conversationmbonnin
04/19/2021, 9:00 PMkotlin-stdlib:1.4.32
and kotlin-reflect:1.3.72
? The compiler tells me strange errors could happen but that doesn't sound very specific. Should I care?bod
04/23/2021, 2:14 PMResult
will be allowed to be returned soon? It's a nice API that we'd like to use, but (unless I'm missing something) currently useless because of this limitation. Just wondering if it's expected to be the case for the foreseeable future.PHondogo
04/27/2021, 5:20 PMdimsuz
04/28/2021, 2:16 PMMutableMap<T, MutableList<R>>
is there a one liner to put an R
into the existing list OR create a list with a single R
, something like
// when map is {}
map.magicOp("one", 3) // → { one: [3] }
map.magicOp("one", 4) // → { one: [3,4] }
Rob Elliot
05/05/2021, 6:18 PMIterable<T>.map
method?
public inline fun <T, R> Collection<T>.map(transform: (T) -> R): List<R> {
return if (this.isEmpty()) emptyList() else (this as Iterable<T>).map(transform)
}
christophsturm
05/11/2021, 3:07 PMLars Vielhauer
05/16/2021, 4:50 PMval map = hashMapOf<Int, Any?>()
println("map.isEmpty() is ${map.isEmpty()}") // true
map[1] = "x"
map[2] = 1.05
// Now map contains something:
println(map) // {1=x, 2=1.05}
From my understanding the last assert is not general enough as the order of elements is not guaranteed, right?
This could maybe be changed to two asserts checking for the two elements separatelypoohbar
05/17/2021, 3:00 PMString.capitalize()
function?Javier
05/17/2021, 9:17 PMUnresolved reference: JvmName
, is it necessary the reflect library now? It is a KMP project with Kotlin 1.5.0gsala
05/20/2021, 8:22 AMResult
is wrapping a failure, the isSuccess
checks return true
. The behavior matches the debugger output there. What could be going on?mbonnin
05/22/2021, 12:42 PMapiLevel=1.3
prevents using ExperimentalStdlibApi
? Is there a way to still allow that? I'd like to use String.capitalize(locale: Locale)
which is stable in 1.4 while still making sure I don't use anything that's only 1.4Brendan Campbell-hartzell
06/03/2021, 7:06 PMthana
06/07/2021, 8:16 AMSequence#take(…)
does contain code examples only for the Iterable#take(…)
method and even mentions variants of take
that do not even exist on Sequence
? https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.sequences/take.htmlchristophsturm
06/10/2021, 11:54 AMuli
06/10/2021, 1:13 PMUByte.toString(radix)
. Was that forgotten? Or is it missing intentionally? (Kotlin 1.5.10)mboudraa
06/11/2021, 6:20 PMResult.getOrThrow
throw a ClassCastException even if the result is successful.
Is there any workaround while the fix is being released. My app depends on it to work properlyDominaezzz
06/17/2021, 9:48 AMcompareBy
requires to much type info up front, at least the overload that takes a selector.bod
06/26/2021, 9:22 AMfun <E> MutableCollection<E>.set(elements: Collection<E>) {
clear()
addAll(elements)
}
fun <E> MutableCollection<E>.set(vararg elements: E) = set(elements.asList())
Zhelenskiy
06/27/2021, 2:55 PMZhelenskiy
06/27/2021, 3:05 PMlouiscad
07/01/2021, 9:33 PMIntRange
would be super useful. One use case is doing text/string replacement (without or with regexes).
Such code:
val offset = -matchResult.range.first
val rangeToReplaceInMatch = (urlGroup.range.first + offset)..(urlGroup.range.last + offset)
could become that one liner:
val rangeToReplaceInMatch = urlGroup.range.offset(-matchResult.range.first)
BTW, I'm doing that in a Kotlin script, where, in a way, adding extra extensions is mostly adding noise to the signal, as scripts are better short for quick understanding.marcinmoskala
07/08/2021, 11:06 AMinline fun <reified T : Enum<T>> enumValueOfOrNull(value: String): T? =
enumValues<T>().find { it.toString() == value }
// or
inline fun <reified T : Enum<T>> enumValueOfOrNull(value: String): T? = try {
enumValueOf<T>(value)
} catch (e: IllegalArgumentException) {
null
}
christophsturm
07/09/2021, 12:02 PMjimn
08/03/2021, 8:57 PM#!kotlin
fun logDebug(debugTxt: () -> String) {
try {
assert(false, debugTxt)
} catch (a: AssertionError) {
System.err.println(debugTxt())
}
}
@ExperimentalContracts
inline fun <T> T.debug(block: (T) -> Unit): T {
contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
}
try { assert(false) } catch (a: AssertionError) {
block(this)
}
return this
}
christophsturm
08/05/2021, 7:59 AMFleshgrinder
08/06/2021, 5:18 PMLuke
08/30/2021, 6:43 PMfun String?.orEmpty(): String
was not defined for CharSequence
? Is it a multiplatform constraint?