Patrick Jackson
05/23/2019, 3:36 PMis () -> Unit
Rak
05/23/2019, 4:03 PMnickk
05/23/2019, 4:39 PMdata class DataDriver<T>(val valueCalculator: (T) -> Int)
val dataDriver = listOf(
DataDriver<T1>( ::calcValue1),
DataDriver<T2>( ::calcValue2)
)
// Using reified worked here
private inline fun <reified T> query(isSubmitted: Boolean): List<T> {
return realm.where<T>().equalTo("submitted", isSubmitted).find()
}
fun calcValue1(item: T1) -> Int {
return 42
}
// But what about here?
// Apply transforms to get a list of calculated items,
// calling the proper query and calculator based on the type.
// Without resorting to type checks for each type.
// IS THIS POSSIBLE?
dataDriver.map {
query() // type inference fails here
.map(::valueCalculator)
}
Lou Morda
05/23/2019, 4:43 PMLeoColman
05/24/2019, 1:35 AMIaroslav Postovalov
05/24/2019, 6:38 AMclass Foo<T = Any>(val t: T = Any())
...
Foo()
elect
05/24/2019, 11:04 AMoverride fun equals(other: Any?): Boolean = when(other) {
this -> true
will other
checked using == or === ?Joao Birk
05/24/2019, 1:11 PMnickk
05/24/2019, 1:28 PMuser
05/24/2019, 2:03 PMNikky
05/24/2019, 4:26 PMGarouDan
05/24/2019, 6:13 PM1.3.40-eap-32
but my build is failing with something like:
Could not resolve org.jetbrains.kotlin:kotlin-test-common:1.3.40-eap-32.
> Could not get resource '<https://dl.bintray.com/kotlin/kotlin-eap/org/jetbrains/kotlin/kotlin-test-common/1.3.40-eap-32/kotlin-test-common-1.3.40-eap-32.module>'.
> Could not GET '<https://dl.bintray.com/kotlin/kotlin-eap/org/jetbrains/kotlin/kotlin-test-common/1.3.40-eap-32/kotlin-test-common-1.3.40-eap-32.module>'.
> <http://dl.bintray.com|dl.bintray.com>
Is this the expected behavior for now? Until it is not released?daggerok
05/25/2019, 5:13 PMdaggerok
05/25/2019, 9:33 PMsrc/test/kotlin
folder?
I prepared an example you can quickly clone and verify:
git clone <https://github.com/daggerok/mixed-kotlin-java-jupiter-tests> testme ; cd $_ ; mvn test
here kotlin tests could be recognized from both stc/test/kotlin
as well as from src/test/java
, but java test classes are visible only from src/test/java
Let me know if you know how to tell maven in it’s pom.xml project build configuration also recognize java tests classes from src/test/kotlin
directory too
ThanksMatej Drobnič
05/26/2019, 8:04 AMCoroutineScope
(needed by convention) quite awkward to call.stanislav
05/26/2019, 12:52 PMmingkangpan
05/26/2019, 2:54 PM@SqlMarker
object SQLBuilder {
fun query(init: SqlSelectBuilder.() -> Unit): SqlSelectBuilder {
val builder = SqlSelectBuilder()
builder.init()
return builder
}
}
I have this, but somehow the compiler still let me do this eventough I marked it with DSLMarker
val query = SQLBuilder.query {
query {
}
what am I doing wrong? 😞Lulu
05/26/2019, 9:19 PMfangzhzh
05/27/2019, 3:05 AMLorin
05/27/2019, 7:32 AMfun main(args: Array<String>) {
fun <P1, P2, R> ((P1, P2) -> R).partial(p1: P1): (P2) -> R = { p2: P2 -> this(p1, p2) }
fun regexMatch(re: Regex, s: String): Boolean = re.containsMatchIn(s)
val match = ::regexMatch.partial(Regex("^123"))
println(match("12345"))
println(match("123xx"))
println(match("2345"))
println(match)
println(match.reflect()!!.run {
"(${parameters.map { it.type }.joinToString()}) -> $returnType" })
}
The output (the signature of match
) is (P2) -> R
.
Is there any way to infer the actual correct signature which should be (String) -> Boolean
?Jan
05/27/2019, 10:24 AMAdrián
05/27/2019, 1:40 PMsealed class MyModel {
abstract val name: String
abstract val title: String
}
data class Model1(
override val name: String,
override val title: String,
) : MyModel()
...
data class Model100(
override val name: String,
override val title: String,
) : MyModel()
If you want to modify the title, for example, adding the environment where you are running your code could be similar to: fun MyModel.addEnvironmentToTitle(env: String) = when (this) {
is MyModel1 -> copy(title = title + env)
... -> // Same boilerplate here
is MyModel100 -> copy(title = title + env)
}
It is a simple example but you could have more complex code and it becomes unmanageable.
Does anyone know if we will have in the future an option to restrict Sealed classes implementation to Data classes? With that restriction previous method would be: fun MyModel.addEnvironmentToTitle(env: String) = copy(title = title + env)
Tuan Kiet
05/28/2019, 6:22 AMcan not mock this method with return type String but got Url instead
galex
05/28/2019, 9:34 AMamadeu01
05/28/2019, 12:43 PMAdrián
05/28/2019, 2:36 PMdumptruckman
05/28/2019, 6:23 PMbbaldino
05/28/2019, 6:59 PMmp
05/28/2019, 8:11 PMAtendra Singh
05/29/2019, 2:05 AM