jimn
07/21/2020, 5:38 AMNikky
07/21/2020, 7:49 AM".*".toRegex()
is regex and marks the string as such so that highlighting works?
is this something i can define on a function wit the right annotations?
ps: lees like @Language("LANGUAGE_ID")
works on preoperties.. sadly not on extension properties or extension functions it seems
either way jsonpath is not in the list of supported things
but this should still be very useful laterRob Murdock
07/21/2020, 2:00 PMpp.amorim
07/21/2020, 5:13 PMe: org.jetbrains.kotlin.codegen.CompilationException: Back-end (JVM) Internal error: Failed to generate expression: KtProperty
In the code below:
private val foo: Foo = object: Foo() {
override fun bar(results: Results) {
val results: List<Zed>? = safeCast(results.values)
}
private inline fun<reified T> safeCast(values: Any): List<T>? =
(values as? List<*>)?.filterIsInstance<T>()
}
Is that because the inline fun
inside the object
? Foo
is a Java abstract class
Mina Makram
07/21/2020, 8:45 PMz3ntu
07/22/2020, 2:03 PMabstract class TestClass(open val value: Any)
class TestClass2(override val value: UInt) : TestClass(value)
val instance = TestClass2(0x1234u)
println("value: ${instance.value}")
I'm getting this exception:
java.lang.ClassCastException: java.lang.Integer cannot be cast to kotlin.UInt
at Scratch_1$TestClass2.getValue(scratch_1.kts:2)
at Scratch_1.<init>(scratch_1.kts:5)
Sean Najera
07/22/2020, 4:19 PMMarc Knaup
07/22/2020, 4:54 PMpp.amorim
07/22/2020, 5:59 PMList.take(n)
and I setup the iterator
of the mocked list and populated it. I thought it could be enough, but I am getting NPE.
`when`(mockedList.iterator()).thenReturn(list.iterator())
I noticed that take
creates a new arraylist by doing val list = ArrayList<T>(n)
. could be the problem here?TwoClocks
07/22/2020, 6:04 PMKClass
that extends a sealed class. Is there anyway to specify this at compile-time, or is this a run-time check?pp.amorim
07/22/2020, 8:10 PMMarshall
07/23/2020, 4:27 PMinterface ErrorCheck<T> {
fun isValid(item: T): Boolean
}
class PropertyRangeCheck<T, R : Comparable<R>>(val prop: KProperty1<T, R>, val range: ClosedRange<R>) : ErrorCheck<T> {
override fun isValid(item: T) = range.contains(prop.get(item))
}
class PropertyStringLengthCheck<T>(val prop: KProperty1<T, String>, val range: IntRange) : ErrorCheck<T>{
override fun isValid(item: T) = range.contains(prop.get(item).length)
}
Alberto
07/23/2020, 4:33 PMNir
07/23/2020, 6:09 PMJim
07/23/2020, 9:21 PMTwoClocks
07/23/2020, 11:34 PMTwoClocks
07/24/2020, 12:09 AMlistOf(1,2,3,4).fold("") { acc, i -> acc }
but this doesn't listOf(1,2,3,4).fold("") { acc, i -> { acc } }
Or put another way : How do I write fold that is multi-statements and has some variables?TwoClocks
07/24/2020, 5:17 AMAndrew Gazelka
07/24/2020, 6:30 AMGUI
which groups together `GUIComponent`s. Each GUI
has a onExit()
method that is called when the user tries to exit the GUI
.
• suppose I have GUI
with a counter
and every time a user GUIComponent
is (A) clicked or the (B) user exits a GUI
the counter
should be increased. Once counter
reached a threshold
, AnEvent
occurs
how should I structure this?
WAY 1 Right now I almost might think of having GUIWithCounter(val counter: Int) : BaseGUI(...)
and each time (A | B) occurs we open GUIWithCounter(counter+1)
• this hard because there is a lot of logic which goes into the creation of BaseGUI
… therefore, when creating it we’d want to use a factory method instead. In Kotlin, we can’t extend a class by using factory methods
WAY 2 We could have GUIWithCounter : GUI
(here GUI
is an interface) … we’d create an instance of BaseGUI
with factory methods with desired arguments… and then use strategy pattern (delegate GUI
methods to the instance of BaseGUI
) .. this seems nice and dandy but here we’d need BaseGUI
to be a concrete class. Therefore, we’d need a onExit()
function in BaseGUI
that does nothing/throws UnimplementedException
(probably not an issue… but this is obv bad code. Perhaps BaseGUI
would instead take a GUIEventHandler
interface in the constructor and delegate onExit()
to implementation defined there. Maybe just me but handlers seem like they could get messy with a bunch of object: …
in code.)
WAY 3 I don’t think this is a good idea???… but we could also have a GUICounterState
and have a function which creates a BaseGUI
with a handler and components that increment the GUICounterState
. The GUICounterState
would then have a detection method to see when counter
has gone over a specific threshold.
Thoughts?Alberto
07/24/2020, 3:38 PMPacane
07/24/2020, 4:06 PMbbaldino
07/24/2020, 5:35 PMT
bounded by Any
and call a method which returns a T
, but in this case T
is a java type (an enum) and the method (defined in java) returns null. I expected an exception to be thrown here, but instead the value of null trickles up just fine, and a (kotlin) method which is set to return a value T : Any
ends up happily returning null. Is it expected that this won't throw somewhere? Is this just a limitation of interacting with Java types from kotlin?Manuel Pérez Alcolea
07/24/2020, 6:06 PMby
exists.
So, my idea was to have, for example, something like this...Joshy Josh
07/24/2020, 10:17 PMfun <T> screen(init: T.() -> Unit): T = init as T
Then eventually extend it have bounds, but for now. I keep getting a casting error. I’m assuming because it’s not invoking init, but I can’t seem to figure that part out.Marc Knaup
07/25/2020, 9:56 AMsomeLong.toIntOrNull()
would be nice if the value is out of rangeahmad abas
07/25/2020, 10:32 AMswiftUI
of kotlin for androiddf
07/25/2020, 6:07 PMdata class Dummy(val namespace: String, val key: String, val value: String)
val dummies = listOf(...)
// do sth. with dummies
// expected: Map<String (namespace), Map<String (key), String (value)>>
jeggy
07/25/2020, 8:11 PMval data: Map<Int, Pair<String, String>> = mapOf(
25 to ("Hello" to "World")
)
data.map { (num: Int, (hello: String, world: String)) ->
// ...
}
How come something like this is not valid code?andylamax
07/26/2020, 6:09 AMlistOf<T>()
and arrayListOf<T>
. And while we are at it I would like to know more about the differences of
1. setOf<T>()
and hashSetOf<T>()
and linkedSetOf<T>()
2. mapOf<T>()
and hashMapOf<T>()
and linkedMapOf<T>()
Also why, List<T>
has no factory methods called linkedListOf<T>()
Mehdi Haghgoo
07/26/2020, 10:44 AMval (a, b) = fun{}
Could someone tell me please what this usage is? Is this an assignment? Why is this crazy usage even legal?
Sorry I know Kotlin is great but it sometimes make me feel stupid 😞Mehdi Haghgoo
07/26/2020, 10:44 AMval (a, b) = fun{}
Could someone tell me please what this usage is? Is this an assignment? Why is this crazy usage even legal?
Sorry I know Kotlin is great but it sometimes make me feel stupid 😞Milan Hruban
07/26/2020, 10:50 AMDavid Hernando
07/26/2020, 11:01 AMstate { DrawerState.Closed }
see https://developer.android.com/reference/kotlin/androidx/compose/package-summary#state
it grabs the type of the return in the init lambdaandylamax
07/26/2020, 11:05 AMMehdi Haghgoo
07/26/2020, 1:16 PMDavid Hernando
07/26/2020, 2:39 PMbrandonmcansh
07/26/2020, 9:08 PM