basher
12/01/2019, 6:11 PMsteenooo
12/01/2019, 7:56 PMGautam Lad
12/01/2019, 8:30 PM@Serializer(forClass = Date::class)
internal object DateSerializer : KSerializer<Date?> {
Hullaballoonatic
12/01/2019, 10:56 PMkarelpeeters
12/01/2019, 11:05 PMKonstantin Petrukhnov
12/02/2019, 6:06 AMfrogger
12/02/2019, 8:46 AMPATCH
method where clients can update the properties they want. `null`would be also an allowed value. I'm using the jackson mapper currently and "property not send" and "property is `null`" looks currently the same when using a normal `data`class.Ashutosh Panda
12/02/2019, 12:59 PMMelvin Biamont
12/02/2019, 1:40 PMsuspend
function and lambdas:
Sometimes, I use lambdas in suspend functions, and inside the lambda, I would like to call another suspend function like this:
class A(
private val b: B,
private val c: C
){
suspend fun doSuspendSomething() {
b.doSomethingElse {
c.doAnotherThing() //Doesn't work because lambda is not suspend
}
}
}
interface B{
suspend fun doSomethingElse(callback: ()-> Unit)
}
class BImpl: B{
suspend fun doSomethingElse(callback: ()-> Unit){
callback()
}
}
class C {
suspend fun doAnotherThing() {
println("I do something very different.")
}
}
So, my problem is the following:
If I simply do:
interface B{
suspend fun doSomethingElse(callback: suspend ()-> Unit)
}
It won’t work in Unit tests using Mockito (I think it’s because in Java, it add a parameter continuation
).
So, another solution would be to use an inline function like this.
interface B{
suspend inline fun doSomethingElse(callback: ()-> Unit)
}
But, it doesn’t work, we can’t inline a virtual function.
Does someone have a solution here?Steve
12/02/2019, 5:02 PMSteve
12/02/2019, 5:42 PMKroppeb
12/02/2019, 5:42 PMAndreas Jost
12/02/2019, 5:45 PMview.onLoginListener = {
launch {
val user = view.userTextField.getTextProperty()
val pass = view.passTextField.getTextProperty()
val result = doLogin(user, pass)
// ...
}
}
It works perfectly fine on Android and iOS devices, but I can't get tests running. If I invoke view.onLoginListener in the test function, nothing happens. The presenter doesn't run the code block. Here is an excerpt of my test class: (see reply in thread)Fudge
12/03/2019, 12:19 AMclass Foo(val callback: (() -> Unit)? = null) {
init {
if (callback != null) {
callback() // Error: Reference has a nullable type '(() -> Unit)?'
}
}
}
This works fine:
class Foo(callback: (() -> Unit)? = null) {
init {
if (callback != null) {
callback() // Error: Reference has a nullable type '(() -> Unit)?'
}
}
}
And this too:
class Foo(val callback: (() -> Unit)? = null) {
init {
if (callback != null) {
callback.invoke()
}
}
}
ursus
12/03/2019, 5:01 AMJoey
12/03/2019, 5:32 AMlaunch{}
and it looks a bit messy in my point of view. Any suggestions?ursus
12/03/2019, 5:33 AMursus
12/03/2019, 6:53 AMfun RecyclerView.Adapter<*>.ifHasFlag(flags: Int, flag: Int, body: () -> Unit): Boolean {
return if (flags.hasFlag(flag)) { <--- replace flags with this
body()
true
} else {
false
}
}
so the callsite within any Adapter looks like
fun onBindHolder(..., payload) {
payload.ifHasFlag(FLAG) {
...
}
}
galex
12/03/2019, 10:54 AMRick
12/03/2019, 11:23 AMBurkhard
12/03/2019, 11:51 AMAshutosh Panda
12/03/2019, 12:12 PMKroppeb
12/03/2019, 12:17 PMMove lambda argument into parentheses
to work if the code it's run on has syntax errors. If so why give the option to do so if there are errors?Ruckus
12/03/2019, 5:06 PMTODO()
throw an Error
instead of an Exception
?
The KDoc for NotImplementedError
says:
> An exception is thrown to indicate that a method body remains to be implemented.
(It's extra weird considering error()
throws an Exception
)bbaldino
12/03/2019, 6:45 PMoverride fun <T : Any> getterFor(valueType: KClass<T>): (String) -> T {
if (valueType.isSubclassOf(Enum::class)) {
// Need to call a method which expected KClass<T> where T : Enum<T>
enumHelper(valueType)
}
...
}
i can detect it's an enum, but can't figure out how to cast 'valueType' correctly such that it can be passed to a function which expects a KClass<T>
where T : Enum<T>
ec
12/03/2019, 7:45 PMSylvain Patenaude
12/03/2019, 8:55 PMByte
or UByte
literal? I know that val toto: UByte = 128u
works when it's an assignment, but I'm looking to make something like this compile:
while (myUByteArray[index] and 128u == 128u) {
}
without having to do an explicit cast like 128u.toUByte()
.
Thanks!
EDIT: According to https://kotlinlang.org/docs/tutorials/kotlin-for-py/primitive-data-types-and-their-limitations.html, I can't without an explicit conversion. I think I will just put the 128u
into a local val
.Hullaballoonatic
12/03/2019, 9:20 PMHullaballoonatic
12/03/2019, 9:23 PMByte
is a Number
, then why isn't a Bit
/`Boolean`?
Iirc, Boolean
isn't actually stored with just one bit in memory, but does that actually matter?Robert Menke
12/03/2019, 10:00 PMRobert Menke
12/03/2019, 10:00 PMZach Klippenstein (he/him) [MOD]
12/03/2019, 10:06 PMcodeslubber
12/03/2019, 10:38 PM