Дмитрий Цывцын
02/03/2022, 2:30 AMxii
02/03/2022, 8:33 AMJan
02/03/2022, 3:21 PMKarlo Lozovina
02/03/2022, 4:21 PMSkc
02/04/2022, 3:42 AMAdvitiay Anand
02/04/2022, 8:04 AMKenneth
02/04/2022, 9:59 AMtotalDigits(10) fractionDigits(3)
?Mark
02/04/2022, 10:30 AMbuildMap
but please can someone explain why this gives a compilation error (unless I uncomment the null):
fun main() {
buildMap {
if (true) {
println("test")
// null
} else {
put("foo", "bar")
}
}
}
https://pl.kotl.in/sohJmyPiJabbic
02/04/2022, 11:48 AMClass {
fun foo() { // normal method definition }
val foo = { // same method implementation, but its a lambda }
}
Justin Xu
02/04/2022, 6:16 PM'pod install' command failed with an exception:
Cannot run program "pod" (in directory "...../iosApp"): error=2, No such file or directory
I installed cocoapods using ruby2.7.5, and I am on M1 mac, following the troubleshooting guide here(youtrack.jetbrains). My "pod install" command also works in the folder, I am just not sure why this error keeps showing up.nkiesel
02/04/2022, 8:39 PMif (predicate(x)) f(x) else null
?Ansh Tyagi
02/05/2022, 12:45 PMfun xyz(param1,param2,param3...)
and get something like {"param1":param1, "param2": param2 … }
its very laborious and redundant to do mapOf. Any workarounds?Ayfri
02/05/2022, 2:57 PMJan
02/06/2022, 5:54 PMJosh Davis
02/07/2022, 3:24 PMRuckus
02/07/2022, 6:54 PMMichael Langford
02/07/2022, 7:38 PMfun JsonObject.get<reified T : Enum<T>>(key: T): JsonElement {
return this.get(key.name)
}
Hi there, I'm trying to make a generic function that helps make my json parsing a little easier. I'm trying to make it so I can pass any enum, rather than having to make a specific copy of this method for each of the decoding enums I'm using.
It seems I'm messing up the syntax for saying "key is a value of some enum type".
This is the only way I'm using this (to get the name of the key item), so I don't actually care if it's reified if I don't need to do so to implement this function.
Can anyone steer me towards how to write this correctly?
Non generic version:
fun JsonObject.get(key: EntryTypeAADeserializer.CodingKeys): JsonElement {
return this.get(key.name)
}
Tim Oltjenbruns
02/08/2022, 1:55 AMfun <Next, Root> KProperty0<Next>.set(value: Next) = Value<Next, Root>(this, value)
Because KProperty0 is out projected, I don’t get any type checking for the value parameter. If the property is a String, I can put an Int in the value because they both inherit from Any. Is there anything I can do to make the type checking more rigid on this function? Looking for a more invariant type checking.Chang Kenneth
02/08/2022, 6:44 AM//sampleStart
fun main() = runBlocking {
repeat(100_000) { // launch a lot of coroutines
launch {
delay(5000L)
print(".")
}
}
}
Ayfri
02/08/2022, 3:50 PMAdvitiay Anand
02/08/2022, 8:33 PMtomas-mrkvička
02/08/2022, 8:34 PMtry { } catch(e: Exception) { }
just to be sure you don't miss anything even if the bottom API change?Thanks.Razine Ahmed Bensari
02/08/2022, 8:43 PMsuspend
keyword is required for function executed inside coroutines ?Jan
02/08/2022, 8:56 PMBernard Ng
02/09/2022, 3:41 AMsmit01
02/09/2022, 6:31 AMLastExceed
02/09/2022, 12:53 PMBart Kleijngeld
02/09/2022, 3:40 PMimport java.io.File
private fun Format(filename: String): Format? {
// Never mind the implementation here.
}
fun readFiles(files: Sequence<File>): Map<Format, List<Reader>> =
files
.groupBy { getFormat(it.toString()) }
.filterKeys { it != null }
.mapValues { it.value.map { f -> f.reader() } } // ERROR: Type mismatch: inferred type is Format? but Format was expected
Priya
02/09/2022, 8:36 PMOrderedSet
(not sorted) in Kotlin? Any alternatives?Michael Langford
02/09/2022, 9:56 PMfun fetchActivities(userName:String, completion:(List<ActivityEntry>)->Unit) {}
fun fetchMoves(userName:String, completion:(List<MoveEntry>)->Unit) {}
fun fetchScores(userName:String, completion:(List<ScoreEntry>)->Unit) {}
Michael Langford
02/09/2022, 9:56 PMfun fetchActivities(userName:String, completion:(List<ActivityEntry>)->Unit) {}
fun fetchMoves(userName:String, completion:(List<MoveEntry>)->Unit) {}
fun fetchScores(userName:String, completion:(List<ScoreEntry>)->Unit) {}
Igor Milakovic
02/09/2022, 10:06 PMDispatchGroup
, it that helps with googling 🙂Michael Langford
02/09/2022, 10:06 PMOliver.O
02/09/2022, 10:07 PMMichael Langford
02/09/2022, 10:07 PMOliver.O
02/09/2022, 10:11 PMMichael Langford
02/09/2022, 10:12 PMOliver.O
02/09/2022, 10:12 PMMichael Langford
02/09/2022, 10:12 PMfun fetchActivities(userName:String, completion:(List<ActivityEntry>)->Unit) {
// This executes after the network request has completed.
}
Tim Oltjenbruns
02/09/2022, 10:14 PMOliver.O
02/09/2022, 10:15 PMMichael Langford
02/09/2022, 10:16 PMOliver.O
02/09/2022, 10:16 PMcallbackFlow
for more than one result.Tim Oltjenbruns
02/09/2022, 10:17 PMlistOf(
async { function1() },
async { function2() },
async { function3() }
).awaitAll()
Michael Langford
02/09/2022, 10:19 PMTim Oltjenbruns
02/09/2022, 10:20 PMMichael Langford
02/09/2022, 10:21 PMTim Oltjenbruns
02/09/2022, 10:24 PMval activitiesDeferred = async { activites() }
val movesDeferred = async { moves() }
val scoresDeferred = async { scores() }
val activities = activitiesDeferred.await()
val moves = movesDeferred.await()
val scores = scoresDeferred.await()
Michael Langford
02/09/2022, 10:25 PMTim Oltjenbruns
02/09/2022, 10:26 PMdata class FullData(
val activities: Result<List<ActivityEntry>>?,
val moves: Result<List<MoveEntry>>?,
val scores: Result<List<ScoreEntry>>?
)
Michael Langford
02/09/2022, 10:28 PMTim Oltjenbruns
02/09/2022, 10:30 PMis callbackFlow parallelizable?It can be but that depends more on the implementation of your Thread situation that happens behind the scenes. A flow can be set on the IO dispatcher which is a big threadpool. But that won’t really matter because you have your own threads inside the implementations
Michael Langford
02/09/2022, 10:31 PMval activitiesDeferred = async { activites() }
val movesDeferred = async { moves() }
val scoresDeferred = async { scores() }
val activities = activitiesDeferred.await()
val moves = movesDeferred.await()
val scores = scoresDeferred.await()
Tim Oltjenbruns
02/09/2022, 10:32 PMMichael Langford
02/09/2022, 10:33 PMTim Oltjenbruns
02/09/2022, 10:34 PMasync
block is called from.Michael Langford
02/16/2022, 2:43 PM