bod
12/21/2020, 1:51 PMtoString
of some class that belongs to a dependency. For that I'll make an extension, but can't call it toString
for obvious reasons, and I'm not very inspired, can you think of a good name? betterToString()
/ toExtraNiceString
/ toEnhancedString
/ toDetailedString
... Better ideas? 🙏Scott Whitman
12/21/2020, 3:27 PMReentrantLock.withLock {}
vs. the coroutines Mutex.withLock {}
?Nir
12/21/2020, 5:23 PMŁukasz Bednarczyk
12/21/2020, 7:15 PMandylamax
12/22/2020, 1:46 AMNir
12/22/2020, 10:15 PMpublic inline fun <K, V> MutableMap<K, V>.getOrPut(key: K, defaultValue: () -> V): V {
val value = get(key)
return if (value == null) {
val answer = defaultValue()
put(key, answer)
answer
} else {
value
}
}
It seems like either the implementation or the description is wrong:
Returns the value for the given key. If the key is not found in the map, calls the defaultValue function, puts its result into the map under the given key and returns it.
println(mutableMapOf<Int, Int?>(5 to null).getOrPut(5) { 10 })
Prints 10. However, 5 is "in the map" (println(5 in mutableMapOf<Int, Int?>(5 to null)
prints true).
kotlin nulls are very tricky in generic code.df
12/23/2020, 12:22 PMtransform: (Map.Entry<K, V>) -> R
instead of just transform: (V) -> R
?Robert Jaros
12/23/2020, 2:31 PMEric Lekwa
12/23/2020, 4:46 PMzain
12/24/2020, 7:03 AMhisham bin awiad
12/24/2020, 8:01 AMAlexandru Hadăr
12/24/2020, 8:12 AMlawlorslaw
12/24/2020, 3:40 PMmelatonina
12/24/2020, 5:45 PMStateFlow
builders similar to callbackFlow
? I'm trying to transform this code to use a StateFlow
instead of a `Flow`:
fun <T> ObservableValue<T>.values(): Flow<T> = callbackFlow {
val listener = javafx.beans.value.ChangeListener<T> { _, _, newValue ->
offer(newValue)
}
addListener(listener)
awaitClose { removeListener(listener) }
}
Edoardo Luppi
12/24/2020, 6:07 PMHamza GATTAL
12/24/2020, 8:12 PMCircuitRCAY
12/25/2020, 1:37 AMCircuitRCAY
12/25/2020, 1:40 AMfun union(message: String | ByteArray)
Andrew
12/25/2020, 3:19 AMkartikpatodi
12/25/2020, 7:29 AMEsa
12/25/2020, 9:07 PMbuszi0809
12/26/2020, 7:25 PMAhmed Mourad
12/27/2020, 12:14 PMdata class X(val v: String)
If this works X::v
shouldn't this also work X?::v
?hisham bin awiad
12/27/2020, 4:43 PMkotlin
any one faced this before Plz help mePoohrang
12/27/2020, 5:01 PMcaelum19
12/27/2020, 10:07 PMobject
that is quite useful to access statically and dynamically. It has some nested properties and classes, and I am currently serializing it with kotlinx.serialization to save it when the application closes. However for loading, Kotlin does not allow me to assign the object with =, is there a way to assign it anyway or another way to do this? The object again has nested objects inside it, so manually setting each property is a solution I would rather avoid 🙂Peter Ertl
12/28/2020, 3:35 PMAnimesh Sahu
12/29/2020, 3:56 AMMark Fisher
12/29/2020, 10:21 AMinterface HexData
object EmptyHexData : HexData
data class Hex(val q: Int, val r: Int, val s: Int)
interface HexDataStorage<T: HexData> {
fun addHex(hex: Hex)
fun addHex(hex: Hex, data: T): Boolean
}
class DefaultHexDataStorage<T: HexData> : HexDataStorage<T> {
private val storage = LinkedHashMap<Hex, T>()
override fun addHex(hex: Hex) {
storage[hex] = EmptyHexData // <-- ERROR
}
override fun addHex(hex: Hex, data: T): Boolean {
val previous = storage.put(hex, data)
return previous != null
}
}
In the function addHex(hex: Hex), I cannot use "EmptyHexData", and I don't understand why. AFAIU It's a sub-type of HexData, so I thought it would comply with the requirement of being a T
in this case. What's wrong, and how do I fix it?
I tried using a class too, e.g. class EmptyHexDataClass: HexData
but that didn't work either.