Slackbot
02/04/2019, 4:48 PModay
02/05/2019, 10:29 AMotakusenpai
02/05/2019, 1:57 PMinline fun letterInRange(char: Char): Boolean = char.compareTo('a') || char.compareTo('b') ||
char.compareTo('c') || char.compareTo('d') ||
char.compareTo('e') || char.compareTo('f') ||
char.compareTo('g') || char.compareTo('h')
Is there a way to shorten the function a bit more? I mean there are too many cases(and yes its giving an error too....)otakusenpai
02/06/2019, 3:38 PMstephan_marshay
02/06/2019, 11:28 PMreturn foo?.let { doStuff(it, bar, baz) } ?: false
oday
02/07/2019, 2:11 PMsaleCars.sortedWith(compareBy(nullsLast<Double>()) { it.hot_deal_likelihood })
Polina
02/08/2019, 8:43 AMKevin
02/08/2019, 11:13 PMvalidator: ValidationContext.(String?) -> ValidationMessage?
So I think I need to provide a function that takes in a ValidationContext
and gives out a ValidationMessage
, but what is up with the .(String?)
. I don’t understand what the signature of my function should be.Kevin
02/09/2019, 1:09 AMreturn when {
filename.isNullOrBlank() -> context.error("Cannot be blank")
!File(filename).exists() -> context.error("File does not exist")
!File(filename).isFile -> context.error("Not a file")
!File(filename).canRead() -> context.error("Permission Denied")
else -> when (val code = canConnect(filename)) {
SQLiteErrorCode.SQLITE_OK -> context.success()
else -> context.error(code.message)
}
}
I only want to try to open a JDBC connection once I know it’s a valid filepath and all that, but is nesting a when
inside the else
of another when
bad form?Shane Blackburn
02/10/2019, 2:00 PMZargorNET
02/11/2019, 3:28 PMkotlin
private val queue: Deque<() -> Unit> = LinkedList()
fun addJob(req: String, callback: (String) -> Unit) {
this.queue.offer {
callback(req)
}
}
//WILL RUN LATER AT AN UNSPECIFIED POINT OF TIME
fun pullJob() {
val func = this.queue.poll()
if (func != null)
func()
}
But I understood suspended functions in such way that they're there to get rid of the callbacks. So can I beautify this code with suspended functions? If so, how?Kenneth
02/12/2019, 11:51 AMOleh Ponomarenko
02/12/2019, 1:13 PMfor (it in this.list) {
if (it == example) {
//do smth
break
}
}
In Kotlin I use:
this.list.foreach{
if(it==example) //do smth
}
I can't use "break" in foreach. I get an error: "Break & continue is only allowed inside a loop".dG
02/13/2019, 10:41 AMdata class Foo(
val bar : Baz
)
data class Baz(
val smth : String
val zzz : String?
)
How would I enforce zzz
not to be null in Foo (and in Foo only)? Can I achieve a non-nullable zzz
there?Guru
02/13/2019, 11:14 AMguppyfaced
02/13/2019, 4:46 PMdave08
02/13/2019, 4:52 PMJagdish
02/14/2019, 9:40 AMPaul N
02/16/2019, 10:38 PMJubin Kuriakose
02/17/2019, 3:04 PMRobert Jaros
02/17/2019, 3:31 PMsnowe
02/17/2019, 7:36 PModay
02/18/2019, 1:34 PMKevin
02/19/2019, 9:04 PMdata class Attachment(val filename: String?, val mimeType: String?)
val Attachment.isImage: Boolean
get() = this.mimeType?.contains("image") == true
fun Attachment.load(): Image { ... }
I want to keep my data classes as pure and simple as possible, and those extensions are just convenience methods for my UI and not core to the model. But I’m wondering if I should just define those things in the class itself?tohu
02/20/2019, 11:31 AMrequire
and check
? I find them useful especially for testing but I'm wondering if those checks should be removed in production.Oleh Ponomarenko
02/20/2019, 3:35 PMKenneth
02/20/2019, 10:59 PMRegex("""^[\d]{9}$""")
or Regex("""^[\d]{9}${'$'}""")
?jurajsolarml
02/22/2019, 11:32 AMdG
02/22/2019, 12:40 PMval foo : SomeInterface = inputVariable
val bar = if (foo is implA) (foo as implA) else (foo as implB)
Here bar
will be of type SomeInterface. Is it possible to somehow use implementation specific stuff available on both implementations but not on the interface, so bar.fieldOnlyOnImplementations
?harry.singh
02/23/2019, 8:20 AMvar immutableList = listOf(1, 2, 3)
immutableList += 4
Since plusAssign
operator is not defined on a Collection
in Kotlin, what does immutableList += 4
really do. It can't add the element to the the List
as it is immutable unlike ArrayList
. So does it first create a new List
from the plus
operator and then assign it to the reference variable through =
?harry.singh
02/23/2019, 8:20 AMvar immutableList = listOf(1, 2, 3)
immutableList += 4
Since plusAssign
operator is not defined on a Collection
in Kotlin, what does immutableList += 4
really do. It can't add the element to the the List
as it is immutable unlike ArrayList
. So does it first create a new List
from the plus
operator and then assign it to the reference variable through =
?Ruckus
02/23/2019, 8:23 AMimmutableList = immutableList + 4
Note that if this was a mutable list, you'd get an error from ambiguity.harry.singh
02/23/2019, 8:46 AMmutableList = mutableList + 4
and mutableList.plusAssign(4)
would be applicable in this case and hence compiler will generate an error for the ambiguityRuckus
02/23/2019, 8:47 AMkarelpeeters
02/23/2019, 8:51 AMharry.singh
02/23/2019, 9:29 AM+
in immutable list example right?karelpeeters
02/23/2019, 9:30 AMharry.singh
02/23/2019, 9:30 AMplus
operator defined on List
, we would never get compiler error in the case of mutable list for +=
right?karelpeeters
02/23/2019, 9:37 AMRuckus
02/23/2019, 3:25 PM