Draget
12/12/2020, 5:10 PMif (!myMap.containsKey(color) || myMap[color]!!.isEmpty()) return 1
Draget
12/13/2020, 7:41 PMvar (a ,b) = somethingReturningAPair()
But what does not work:
var a: Int
var b: Int
(a, b) = somethingReturningAPair()
Or does it only work when initalizing variables?Chris Overcash
12/14/2020, 8:58 PMLumeidagnacadja
12/16/2020, 12:19 PMalex cole
12/17/2020, 5:49 AMmineLocation = Set<Int>(mineCount) { Random.nextInt(0, length * width)}
keochris
12/17/2020, 5:31 PMDaniele Segato
12/18/2020, 10:04 AMimplementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.2"
But I cannot use async
and launch
in a suspend fun
suspend fun foo() {
async {} // Unresolved reference
launch {} // Unresolved reference
}
What am I missing here?!
EDIT: nevermind, I was remembering it wronly, I need something like coroutineScope {}
or withContext(...)
or something like thatRaul Macías
12/18/2020, 5:51 PMByFloRedstone
12/19/2020, 1:10 PMhazn
12/20/2020, 4:41 PMhazn
12/20/2020, 4:42 PMpoohbar
12/20/2020, 9:13 PMPath
is now the preferred way over File
in Java, why is there no readBytes()
extension on Path
?Daniele Segato
12/21/2020, 3:10 PMMutableStateFlow
for the first time, but it is not doing what I expect
private val state = MutableStateFlow<MyState>(INITIAL_STATE)
suspend fun refresh(): MyState {
val newState = service.refresState()
this.state.value = newState
return newState
}
fun observeState(): Flow<MyState> {
return state
.transform { s ->
if (s !== INITIAL_STATE) {
emit(s)
} else {
refresh() // expecting this to automatically send a new state to the flow
}
}
}
I was expecing the refresh()
to cause a new state to be emitted, but it didn't.
Can someone guide me in the right direction?
thanks.ink
12/21/2020, 7:44 PMfor taks in tasks:
launch { task }
or would it be something like:
launch { task1, task2, ..., taskN }
Animesh Sahu
12/22/2020, 10:07 AMval output = (...)
"""public \w*\s*class (.+)\.(\w+) \{\n([^\}]*)\}$""".toRegex().find(output)
Here's the thing to match against:
Compiled from "Test.kt"
public final class com.github.animeshz.keyboard.jni.Test {
public final native void test(kotlinx.coroutines.flow.Flow<java.lang.Integer>);
public com.github.animeshz.keyboard.jni.Test();
}
Seems that regex is correct according to this https://regex101.com/r/PEv4BL/2Nat Strangerweather
12/23/2020, 9:26 AM32 + 64 + 4 + 128
. The problem is that I don't want the numbers to be added up. If I use quotation marks to turn it into a String, I get an error because the method needs Ints. Any ideas?Daniele Segato
12/23/2020, 12:16 PMFlow.transformLatest()
complete when upstream completes?
upstream
.transformLatest { state ->
emitAll(dataForState(state))
}
say upstream is
currentState
.takeWhile { state -> isCloseNowState(state) }
This would be easy if I had control of it, I could use transformWhile
, what if I don't?
How do I cancel dataForState
when upstream completes?
Actually, this is challenging even when I use transformWhile()
cause it is not cancelling the previous one I'd need a transformLatestWhile
Victor Cardona
12/23/2020, 3:14 PMinternal companion object {
internal val validation = object {
val name_blank: String = "Presenter must have a name"
}
}
The problem I’m having is that the name_blank property is not visible anywhere.
Presenter.validation.name_blank // Error, name_blank not resolved
zsperske
12/23/2020, 6:19 PMpublic static <T> MyFactory<T> of(Class<T> baseType) { ... }
and you wanted to write a kotlin extension method like:
fun <T> MyFactory<T>.withSubTypes(types: List<Class<T>) {
var factory = this
types.forEach { factory = factory.withSubType(it) }
return factory
}
How do you properly type the static method? If you write something like:
val factory = MyFactory.of(MyClass::class.java)
.withSubTypes(listOf(...))
You'll get a syntax error on your list: Type mismatch. Required: Nothing Found: MyClass
. Adding explicit type arguments doesn't help.dan
12/27/2020, 1:41 AMm = mutableMapOf<String, Int>()
m.put("a", 1)
m.put("a", 1) // throw exception here
alex cole
12/27/2020, 2:54 AMF0X
12/27/2020, 12:26 PMMainCoroutineDispatcher
that simply runs the coroutines on an existing main thread?Dmitry Lukianov
12/28/2020, 6:53 PMSudhir Singh Khanger
12/29/2020, 4:05 AMIn Java, arrays store primitive types whereas collections store boxed types. In Kotlin, both arrays and collections store boxed type whereas one can use classes like,IntArray
, etc. to store primitive data type without boxing.ByteArray
Sudhir Singh Khanger
12/29/2020, 5:35 AMintArrayOf()
if one wants to initialize an IntArray
with specific and different values otherwise one can simply use IntArray()
. Is that correct?
* These two are the same
val arr: IntArray = intArrayOf(0, 0, 0)
val arr = IntArray(3)
* IntArray with different values
val arr = IntArray(3)
arr[0] = 1
arr[0] = 2
arr[0] = 3
vs
val arr: IntArray = intArrayOf(1, 2, 3)
xetra11
12/29/2020, 3:36 PMenum class Trait(code: String) {
AMBITIOUS("ambitious"),
HUNTER_1("hunter_1"),
WRATHFUL("wrathful"),
CALLOUS("callous"),
VIKING("viking"),
EDUCATION_MARTIAL_3("education_martial_3")
}
I want to access the code
property as described in this tutorial: https://www.baeldung.com/kotlin-enum
Having this statement
val code = Trait.EDUCATION_MARTIAL_3.code
^^^^^
Where code
Unresolved reference: code
Was the feature removed from the latest Kotlin version or what happened?Nat Strangerweather
12/29/2020, 9:25 PMval notificationManager: NotificationManager =
context.getSystemService(NOTIFICATION_SERVICE) as NotificationManager
But I read that using a context in a View Model is the wrong approach. Is there a solution to this?Tony Blundell
01/01/2021, 11:01 PM0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 < 0.8
evaluates as true, because the left-hand side is actually 0.79r instead of 0.8. What's the best way of dealing with this? I guess I could convert to a string and back, but that feels a little 'hacky'. Is there a better way?Daniele B
01/02/2021, 8:43 PMval numbers = listOf(1,0,4,0,10,14,16,0,0,34,46)
how can I transform it in another list where each number is the maximum so far?
val numbers = listOf(1,1,4,4,10,14,16,16,16,34,46)
Ellen Spertus
01/05/2021, 1:00 AMfor (num in listOf(1, 2, 3)) println(num)
123
Why isn't each element on its own line?