Michael
06/26/2018, 2:29 PMfunc: Function<Foo, Bar>
. Elsewhere in the code, when calling it, I’m trying to pass in { it.baz }
where it is type Foo, and baz is type Bar. But it’s giving me unresolved reference: it
and saying that the type of the lambda is () -> [ERROR:]
. If I prefix it with the word Function, Function { it.baz}
it works.Ron K
06/26/2018, 2:46 PMfun Map<Any, Any>.cast(value: RubyHash) = value.toMap()
. But this doesn't work.Hamza
06/26/2018, 3:45 PMJose Antonio Jimenez
06/26/2018, 4:44 PMrook
06/26/2018, 5:54 PMikt
06/26/2018, 9:25 PMWahib
06/26/2018, 10:14 PMwhen
on a pair
type? Finding it a bit difficult to make it work.
Something like:
val pair: Pair<StatusAType, StatusBType> = ...
when(pair) {
is (StatusA, StatusB) -> {
}
}
It is showing an error Type Expected
in IDEjacob
06/26/2018, 11:25 PMedwardwongtl
06/27/2018, 8:20 AMenum class A {
A, B
}
enum class B {
A, B
}
fun main(args: Array<String>) {
val a = A.A
when (a) {
A.A -> println("A.A")
A.B -> println("A.B")
B.A -> println("B.A") // hit this branch
B.B -> println("B.B")
}
}
ikt
06/27/2018, 9:26 AMclass Async_load<WaitT, ErrorT, DoneT> (
val w: WaitT,
f: Async_load<WaitT, ErrorT, DoneT>.(WaitT) -> Unit) {
var state = Async_load_state.Wait<WaitT, ErrorT, DoneT>(w)
init { f(w) }
fun is_done(): Boolean {
return when(state) {
is Async_load_state.Error<*, *, *> -> true
is Async_load_state.Done<*, *, *> -> true
else -> false
}
}
}
Is there a way to simplify this? I do not want to repeat <WaitT, ErrorT, DoneT> all the timeikt
06/27/2018, 9:26 AMsealed class Async_load_state<WaitT, ErrorT, DoneT> () {
class Wait<WaitT, ErrorT, DoneT>(val wait: WaitT): Async_load_state<WaitT, ErrorT, DoneT>() {}
class Error<WaitT, ErrorT, DoneT>(val error: ErrorT): Async_load_state<WaitT, ErrorT, DoneT>() {}
class Done<WaitT, ErrorT, DoneT>(val done: DoneT): Async_load_state<WaitT, ErrorT, DoneT>() {}
}
class Async_load<WaitT, ErrorT, DoneT> (
val w: WaitT,
f: Async_load<WaitT, ErrorT, DoneT>.(WaitT) -> Unit) {
var state = Async_load_state.Wait<WaitT, ErrorT, DoneT>(w)
init { f(w) }
fun is_done(): Boolean {
return when(state) {
is Async_load_state.Error<*, *, *> -> true
is Async_load_state.Done<*, *, *> -> true
else -> false
}
}
}
Mathias Brandt
06/27/2018, 9:50 AMvar matches = liveMatches.value
if(matches == null) {
matches = ArrayList()
}
Can be shortened to this:
var matches = liveMatches.value ?: ArrayList()
Dariusz Sadowski
06/27/2018, 9:54 AMvar matches = liveMatches.value ?: mutableListOf()
Mathias Brandt
06/27/2018, 10:52 AMval liveChallenge = MutableLiveData<Challenge>()
. I want to expose it as a LiveData<Challenge>
. Should I just make the field private and write a getter, fun getLiveChallenge(): LiveData<Challenge> = liveChallenge
(like I would do in Java) or is there a smarter way?spierce7
06/27/2018, 4:46 PMRuckus
06/27/2018, 5:56 PMval type: Class<T> = ...
val clazz: Class<Any> = ...
val superClazz = clazz.superclass // is Class<in Any!>!
// works fine
if (type == clazz) ...
// won't compile: Operator '==' cannot be applied
if (type == superClazz) ...
Why doesn't that work? Doesn't Class<in Any!>! : Any
still hold true?Slackbot
06/28/2018, 7:52 AMdalexander
06/28/2018, 12:09 PMfun <T> Single<T>.sub(onNext: (T) -> Unit = { }): Disposable
This would be a method that by default has an empty onNext.igorvd
06/28/2018, 12:55 PMif (key in map) {
val value = map[key]!!
}
If I remove the assertion operator, the type of the value
will be ?
Ruckus
06/28/2018, 5:14 PMikt
06/28/2018, 6:14 PMsnowe
06/28/2018, 8:32 PMfatih.yalmanbas
06/29/2018, 8:48 AMnavi
06/29/2018, 10:28 AMMathias Brandt
06/29/2018, 10:47 AMPlayer
objects. Each Player
has a score: Int
. I want to calculate the total score for all players.
Can I do something like
list.reduce { ... }
directly, or do I have to use map as well, e.g.
list.map { it.score }.reduce { sum, score -> sum + score }
karelpeeters
06/29/2018, 1:12 PMopen class Parent(val a: Int, val b: Int)
class Child(val c: Int) : Parent(@inherit)
Child(a = 1, b = 2; c = 3)
ikt
06/30/2018, 3:06 AMrahulrav
07/01/2018, 12:41 AMktor
questionCircuitRCAY
07/01/2018, 12:51 AMursus
07/01/2018, 5:01 AMursus
07/01/2018, 5:01 AMkarelpeeters
07/01/2018, 8:30 AMopen
classes with lots of possible types, just a bit restricted.ursus
07/01/2018, 1:24 PMkarelpeeters
07/01/2018, 1:42 PMursus
07/01/2018, 3:03 PMkarelpeeters
07/01/2018, 3:05 PMgildor
07/01/2018, 3:32 PMursus
07/01/2018, 3:56 PM