Janez Kolar
10/15/2020, 12:40 PMfun nearCar(minLat: Float, maxLat: Float, minLon: Float, maxLon: Float): List<Car> {
return mutableMapCars.values.parallelStream().filter {
it.lat > minLat &&
it.lat < maxLat &&
it.lon > minLon &&
it.lon < maxLon
}.toList()
}
data class Car(
val id : Long,
val registration : String,
val lon: Float,
val lat: Float
)
frankelot
10/15/2020, 2:28 PMBig Chungus
10/15/2020, 4:37 PMbin/kotlinc
found in kotlin-native cli release tar can be used interchangeably with the one found in kotlin-compiler.zip?aarjav
10/15/2020, 9:58 PMxii
10/16/2020, 2:16 AMKamilH
10/16/2020, 8:06 AMdata class
with its default values?
For example I have:
data class User(
val id: String,
val deviceId: String
)
and plugin will generate:
fun userOf(
id: String = "",
deviceId: String = "",
): User =
User(
userId = userId,
deviceId = deviceId,
)
or something similar? (Sorry if wrong channel)eenriquelopez
10/16/2020, 9:36 AMval title: (locale: Locale) -> String? = {
getPrompt(it.language)
}
fun getPrompt(string: String) : String? {
return if (string == "A") null
else "A"
}
getPrompt
can return null, hence the String?
However, the following check returns a warning from the compiler ("the comparation can be simplified since title is never null")
if (title == null) {
}
But title can effectively be null.
Is this a bug on AS/JetBrains?Daniel
10/16/2020, 10:50 AMval parentScope: CoroutineScope
val childScope = parentScope.something()
I want childScope to be cancelled if parentScope is, but for parentScope not to be cancelled if childScope isAnimesh Sahu
10/16/2020, 11:39 AMciscorucinski
10/16/2020, 12:29 PMval pluginGroup: String by project
This will search for .property files for the key pluginGroup
and return it's value as a String
. I am impressed by that, but how the heck does this magic work?
This will only return String
values, so even if we have the following in the .properties file...
platformDownloadSources = true
It will still only return "true"
as a String
.
I am curious of how this mechanism works and why it is limited to only String
and why it is limited to the specific name I have for the variable. Meaning I must name my variable the same as is in the .properties file.streetsofboston
10/16/2020, 2:47 PMclass MyList<T> {
@JvmName("flatMapList")
fun <R> flatMapList(block: Function1<T, List<R>>): MyList<R> = TODO()
@JvmName("flatMapListPair")
fun <R> flatMapList(block: Function1<T, Pair<R, R>>): MyList<R> = TODO()
@JvmName("flatMapList2")
fun <R> flatMapList2(block: (T) -> List<R>): MyList<R> = TODO()
@JvmName("flatMapListPair2")
fun <R> flatMapList2(block: (T) -> Pair<R, R>): MyList<R> = TODO()
}
fun test() {
val x = { it: Int -> Pair("1", "2") }
val y = { it: Int -> listOf("1", "2") }
MyList<Int>().flatMapList(x) // OK
MyList<Int>().flatMapList({ it: Int -> Pair(1, 2) }) // ERROR
MyList<Int>().flatMapList2(x) // OK
MyList<Int>().flatMapList2({ it: Int -> Pair(1, 2) }) // ERROR
MyList<Int>().flatMapList(y) // OK
MyList<Int>().flatMapList({ it: Int -> Pair(1, 2) }) // ERROR
MyList<Int>().flatMapList2(y) // OK
MyList<Int>().flatMapList2({ it: Int -> Pair(1, 2) }) // ERROR
}
Why does the compiler (and IDE) generate an error when directly assigning the lambda, but it compiles fine when using a temporary variable (x
and y
)?Daniel
10/16/2020, 4:35 PMgetTile
, which may need to call renewAccessToken
. If I make ten parallel calls to getTile
, and I need to renew the token, one call should do the renewing, and the rest should block until it is done.
I'm wondering if I want something that emits a stream of (mostly-identical) access tokens, which getTile pulls the latest access token from. The stream then chooses whether to renew or present a stale valuekartik1712
10/17/2020, 10:22 AMCould not create an instance of type org.jetbrains.kotlin.gradle.targets.js.subtargets.KotlinBrowserJs.
Failed to apply plugin [class 'org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin'] > The Kotlin Gradle plugin was loaded multiple times in different subprojects, which is not supported and may break the build.
This might happen in subprojects that apply the Kotlin plugins with the Gradle 'plugins { ... }' DSL if they specify explicit versions, even if the versions are equal.
Please add the Kotlin plugin to the common parent project or the root project, then remove the versions in the subprojects.
If the parent project does not need the plugin, add 'apply false' to the plugin line.
My root build.gradle.kts
does not have a plugin block and my KMM module has the plugin block as follows.
plugins {
kotlin("multiplatform") version Versions.kotlin
application
kotlin("plugin.serialization") version Versions.kotlin
}
NurBahnhof
10/17/2020, 7:08 PMBig Chungus
10/17/2020, 7:53 PMwilliam
10/17/2020, 9:07 PMTomasz Krakowiak
10/18/2020, 11:06 AMGieted
10/18/2020, 1:44 PMDaniel
10/18/2020, 3:37 PMasync
Unresolved reference. None of the following candidates is applicable because of receiver type mismatch:
public fun <T> CoroutineScope.async(context: CoroutineContext = ..., start: CoroutineStart = ..., block: suspend CoroutineScope.() → TypeVariable(T)): Deferred<TypeVariable(T)> defined in kotlinx.coroutines
I'm not sure how much I can pare down my example, because it seems pretty specific to what I'm trying to do. Here's essentially the function
suspend fun getTile(params: SomeType): GetTileResponse {
val cached = tileCache.get(params)
if (cached != null) {
return GetTileResponse.Available(cached)
}
val request = GetTileRequest(params)
val deferred = async {
makeRemoteRequest()
.map { convertIntoResponse(it) }
}
return GetTileResponse.Loading(deferred)
}
If I ask kotlin to generate an implementation of async, I get something which seems to look very similar to the definition of async (https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/async.html)
private fun async(block: suspend CoroutineScope.() -> Either<GetTileError, Bitmap>): Deferred<Either<GetTileError, Bitmap>> {
TODO("Not yet implemented")
}
Simon Lin
10/19/2020, 6:41 AM[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
and random sub list size range from 0 to 4.
output: [0, 1]
[2, 3, 4, 5]
[6]
[]
[7, 8]
[]
[9, 10]
Each sub list size is random.Edoardo Luppi
10/19/2020, 9:54 AMproviders.forEachIndexed { index, provider ->
if (index == 0) {
whatsNewPanel.setProvider(provider)
}
...
Is there a function/extension which lets me move that whatsNewPanel.setProvider(provider)
in a separate space? Possibly in the same call chainspand
10/19/2020, 10:59 AMgradle build
and IDEA would use it on build. Anyone tried something similar? I guess what I would like is the ability to set a custom -P
or -D
property for IDEA taskshallvard
10/19/2020, 11:08 AMlateInitVar.isInitialized()
from java?Nick
10/19/2020, 5:20 PMfun f(a: String){
sendData()
//some a.length call (throws NPE)
}
with intrictics removed 'sendData' method will be executed.
Another persons position is that business logic should be explicitly checked with some require(a!=null) check and developers should not rely on intrictics.
What do you think?Daniel
10/19/2020, 6:03 PMDaniel
10/19/2020, 6:20 PMfun bitLength(n: Int) = floor(log2(n.toFloat())).toInt() + 1
fun combine(vararg numbers: Int): Int {
var total = 0
var prevBitLength = 0
for (num in numbers) {
total += num shl prevBitLength
prevBitLength += bitLength(num)
}
return total
}
Simon Lin
10/20/2020, 7:21 AMfun main() {
val stringDouble = "420.0"
val int = stringDouble.toIntOrNull()
assert(int != null) // failed
}
Hai Tran
10/20/2020, 10:00 AMPeter Ertl
10/20/2020, 10:58 AMPeter Ertl
10/20/2020, 10:58 AMMarc Knaup
10/20/2020, 11:00 AMcoroutineScope { … }
.
It will automatically wait until all Jobs are completed or throw on first job failure.Peter Ertl
10/20/2020, 11:01 AMMarc Knaup
10/20/2020, 11:21 AMStephan Schroeder
10/20/2020, 3:54 PMPeter Ertl
10/21/2020, 10:15 AM