Ifvwm
05/25/2020, 1:36 AMIfvwm
05/25/2020, 3:05 AMfun Int.foo(){}
?Ifvwm
05/25/2020, 3:06 AMfun foo(): Int {}
Ananiya
05/26/2020, 12:36 PMmust not have replace block. For dynamic query parameters use @Query
.how do i fix this error?myaa
05/27/2020, 1:48 AMalso
runs a function and then returns the original value, except that i only want to run the function if the original value is null
i've got something like
value.takeIf { it >= 0 } ?: run { println("Warning: negative value"); null }
except i'd like to avoid manually having to return null at the end of the run
Paul N
05/27/2020, 10:21 AM@Test
fun `test filter`() {
val cars = listOf("1" to "Jag","2" to "Mini")
val ids = listOf("1","2","3")
val validIds = ids.filter { cars.map { it.first }.contains(it) }
validIds `should equal` listOf("1","2")
}
Bernhard
05/27/2020, 10:33 AMKarlo Lozovina
05/27/2020, 2:26 PMKarlo Lozovina
05/27/2020, 2:43 PMMarc Knaup
05/27/2020, 5:32 PMCannot access class ’<class>’. Check your module classpath for missing or conflicting dependenciesWhat does this even mean exactly? I want to test code that depends on a certain library. But I cannot add that library to the test configuration, so I simply create some dummy classes with the same name & package name and mock them using mockk 🤔 Doesn’t seem to work though 😅
viralshah
05/28/2020, 12:41 AMval startTime = Instant.ofEpochMilli(1589778000000).atZone(ZoneOffset.UTC) // May 18 @ 05:00 UTC
val endTime = Instant.ofEpochMilli(1589950800000).atZone(ZoneOffset.UTC) // May 20 @ 05:00 UTC
val res: List<ZonedDateTime> = startTime.hoursUntil(endTime)
//[May 19 05:00, May 19 06:00 ...]
So that I can do a group by day on it
val final = res.groupBy{it.day}.toMap()
{ May 18 -> 19 hours , May 19: 24 hours, May 20: 5 hours}
Is this possible?Brumelis Martins
05/28/2020, 7:08 AMCoroutineScope(Dispatchers.Main).launch {
withContext(<http://Dispatchers.IO|Dispatchers.IO>) {
// do something here
}
}
It always stops after withContext(Dispatchers.IO), im adding the TestCoroutineDispatcher @rule but it still does not work.Jody
05/28/2020, 10:52 AMreified
method and my Mockito is presumably choosing the wrong method for some reason. So when running my tests, Mockito either chooses the method I want to mock or chooses the reified
Kotlin method, which then turns into an Exception because the return types do not match. Did someone run into this problem already or know how to fix this?elect
05/28/2020, 12:14 PMList
?Jukka Siivonen
05/28/2020, 12:55 PMJamie Taylor
05/28/2020, 3:10 PMSam Garfinkel
05/28/2020, 3:11 PMmyaa
05/28/2020, 6:20 PMclass Test(
first: String = "default",
second: Int = 42,
third: Boolean = false
) {
val map = mutableMapOf<String, Any>()
inner class MyDelegate(private val default: Any) {
operator fun getValue(receiver: Test, property: KProperty<*>) =
map.computeIfAbsent(property.name) { default }
operator fun setValue(receiver: Test, property: KProperty<*>, value: Any) {
map[property.name] = value
}
}
var first by MyDelegate(first)
var second by MyDelegate(second)
var third by MyDelegate(third)
}
val t = Test(second = 100)
t.first = "test"
println(t.map) // {first=test} - WRONG
println("${t.first} ${t.second} ${t.third}") // test 100 false
but i don't like the redundant definitions (having to declare each field as an argument as well), and this example also behaves incorrectly in that the map doesn't get populated with all the arguments immediately upon instantiationketurn
05/28/2020, 6:28 PMproject { all X@{ register {
foo(this@X)
}}}
is there a way for that inline receiver function to give the receiver an explicit name, other than this
, instead of using the @
label?Gabe Kauffman
05/28/2020, 11:06 PMString
?
Example, putting a function like this globally scoped in like a StringUtils.kt
class:
fun String.getLinkIfPresent(): String? {
val m: Matcher = urlPattern.matcher(this)
if (m.find()) {
return m.group().trim()
}
return null
}
myaa
05/28/2020, 11:17 PMChild1
can be "accessed" using a Child1Accessor<T>
object, which will return a value of type T
.
abstract class Accessor<T>
abstract class Parent<A : Accessor<*>> {
fun <T> access(accessor: Accessor<T>) : T = TODO("implement")
}
class Child1Accessor<T> : Accessor<T>()
class Child1 : Parent<Child1Accessor<*>>()
class Child2Accessor<T> : Accessor<T>()
class Child2 : Parent<Child2Accessor<*>>()
val myIntVal: Int = Child1().access(Child1Accessor<Int>())
val myStringVal: String = Child1().access(Child1Accessor<String>())
val error: Int = Child2().access(Child1Accessor<Int>()) // should be an error, wrong type of accessor
my issue is: how do i restrict the accessor
parameter of access
to be a subclass of A
, the accessor type specified for that class, without using wildcard types, so that i know the type parameter of the accessor?
i tried the following:
fun <T, V> access(accessor: V) : T
where V : A,
V : Accessor<T> = TODO("implement")
but this gives me a Type parameter cannot have any other bounds if it's bounded by another type parameter
errorAli
05/29/2020, 5:17 AMaaverin
05/29/2020, 12:32 PMnull
is not supported by RxJava and RxKotlin, what is the strategy you use to have kind of null values?
We have some places in codebase that were doing something like
map {
service.get() //can return null
}.filterNotNull()
It's too much effort to rewrite every service to not ever return null when before null was considered a valid empty value.iguissouma
05/29/2020, 2:27 PMxii
05/29/2020, 4:37 PMList<Test?>
and I want it to be just a List<Test>. how do I prevent the type of the elements in the list to be nullable? I want it to be an empty list worst case scenarioSebastien Leclerc Lavallee
05/29/2020, 6:03 PMpublic final GoogleSignInOptions.Builder requestScopes(Scope var1, Scope... var2) { }
I can call .requestScopes(scope1, scope2, scope3)
without any problem.
How can I translate a list of Scopes to call this function. I tried using only an Array
, a List
, to pass the first element and then a list. But nothing worked. Seems like I have to pass the expanded list. How can I achieve this when my list of scopes is stored inside a List<Scope>
?
Thanks!Steve
05/29/2020, 9:51 PMsealed class Amount(
val currency: Currency,
val value: Long,
val type: String
) {
data class Sold(override val currency: Currency, override val amount: Long): Amount(currency, amount, "Sold)
NurBahnhof
05/29/2020, 9:58 PMapplication{ mainClassName="SomeClass" }
where do the name mainClassName come from? I'm setting some attribute here. But where is the object? Shouldn't it be something like:
application.mainClassName="SomeClass"
ClaudiuB
05/29/2020, 9:59 PMkotlin.collections.ArrayList.indexOf
. I think it's critical, but maybe not. There are fixes but indexOf
doesn't properly work for me in certain cases ( version 1.3.61)
Premise: val questionsAndAnswers = mutableListOf<Any>()
, in practice containing items of types data class Answer and data class Question. Both have equals(other: Any)
overriden to return true only when other is of the same type.
equals in Answer
override fun equals(other: Any?): Boolean {
return (other as? Answer)?.proof?.sourceNode?.getContentId() == proof?.sourceNode?.getContentId()
}
equals in Question
override fun equals(other: Any?): Boolean {
return (other as? Question)?.item?.getContentId() == item?.getContentId()
}
I do questionsAndAnswers.indexOf(answer)
knowing my answers are only add odd indexes, and I get a 0. I expected either -1 or odd. Check the debugger, i mapped a bunch of data to help troubleshootShawn Karber_
05/29/2020, 10:11 PMdevice.establishConnection(false)
.flatMap(rxBleConnection -> Observable.combineLatest(
rxBleConnection.readCharacteristic(firstUUID),
rxBleConnection.readCharacteristic(secondUUID),
YourModelCombiningTwoValues::new
))
.subscribe(model -> {
// Process your model.
});
Here's the code I am trying to write:
device.establishConnection(true)
.flatMap { rxBleConnection ->
val characteristicReads: MutableList<Single<ByteArray>> =
mutableListOf()
for (c in characteristics) {
characteristicReads.add(rxBleConnection.readCharacteristic(c.uuid))
}
Observable.combineLatest(*characteristicReads)
}
.subscribe({ onConnectionSuccess(it) }, { onConnectionFailure(it) })
The error is:
Type mismatch.
Required: ObservableSource<out TypeVariable(R)!>!
Found: Unit