LastExceed
11/16/2021, 12:46 PMhttps://i.imgur.com/rfsvzox.png▾
Manuel Dossinger
11/16/2021, 2:00 PMmyList.filterNotNull().filter { f(it) }
, but that would essentially loop through the list twice, correct?Colton Idle
11/17/2021, 2:02 AMdata class Person(
val name: String = "",
)
but if firestore sends null
, then even though the type is non-null, if I put a breakpoint... I can see that I do actually get a null value?
Question: How can a non-null property like name
be null? I'm assuming this is because of reflection/java-interop or something?Michael Langford
11/17/2021, 6:28 PMenum class AdmininstrationReason {
Prophy,
StudyPlacebo,
LightTherapy,
DrinkingRelated, //<- We might want to display this as "Swallowing Disorders"
Clotting,
Other;
}
So I certainly can implement it as above and then use automatic parcelize/@Parcelable stuff and it works.
I can even add an annotation and then get clever when displaying the value. This causes a performance hit by possibly dipping into reflection.
I can make a companion object and use associatedBy to get part of the way there, but this breaks automated parcelization.
I can make vals with getters for specific properties and use that, but it makes the per-item edits non-local to the list.
I could make every item have a "String" value with it, but I don't want to have to add strings for some of these entries (of which there are hundreds) and duplicate the name of the items in an error prone matter.Alejandro Rios
11/17/2021, 8:18 PMjbnizet
11/18/2021, 7:38 AMdata class Foo(val bar: String)
. In IntelliJ , selecting Foo
and hitting Alt-F7 only searches for the usages of the constructor. How do I make it search for all the usages of the class Foo?Mendess
11/18/2021, 12:07 PMsealed class Result<out T> {
class Success<out T>(val value: T): Result<T>()
class Failure<out T>(val error: MyError): Result<T>()
fun orDefault(d: T): T = when (this) {
is Success<T> -> this.value
is Failure<T> -> d
}
}
I understand why it doesn't work, T is in in
position when I marked it as out
, what I want to know is: Is there some syntax to make T
invariant or contravariant just for that method?Bart Whiteley
11/18/2021, 4:50 PMBassam A.
11/18/2021, 6:26 PMAyfri
11/19/2021, 4:33 PMselection
) that is equal to this pattern : [key=value, key=value, key=value]
and I want to split it to a map containing all the keys and values, is there a simple way than this ?
val attributes = selection.replace("[(\\w+)]".toRegex(), "$1").replace("\\s+".toRegex(), "").split(',').associate { it.substringBefore('=') to it.substringAfter('=') }
Eric Boggs
11/19/2021, 8:14 PMfun main() {
// fake key
val key: String = "N39w7DKQplfbMH6dD3WJQDG7SnR0QTznHTPn04F73TOxePLIZS924FGLszocSHV70HAlnrbSuKAkoQQpgTEDANTFPvQQxpUm7bHtW91zVBfFbJZYxP79vEPUGnOGOpWkix8GTwQpInSG8jSU3hxFbQXIewT7UvNX5ZvZXkLkmKtNqb6vjNiRCtk1fWQnCsCaCUIDHkNRigOjWKES15I81oF8qgS88vNuGix4SVPzGxW1GaUuGNWyRrQ2FXy5GAxITaVQgoTmu5OIjH5hWPIGpt0CdRIJFON770iX4Rqin6utcKZiainwC7rhuRsZw5zhO2uSA1di3ucGd2VeLgCcBnnJghZfCLioyUSPq4cImsmm3PWmo0CSAe7bJEKxvzTwoPsXRC8vuMSr9EpPRBudhvn0xGSB98MEC6ADao07cp8mIXJy9EDQofUddtutsAesg5jhSkN8N1yTg8CwcpXDFckgTZ2jV91iZjNhByY0pAaafg7d4esNLhbLTJCHV8Jq3Txen1rNOYkjfKlZfwolxprIYcKaPqYNkXnufutDGhEBaJFjXwO4en2G0RUMIBiWo2XhnjQjPs6YbLgQbwSmTewPzL8w4INbbGVxtLRdkNSnfOCT94WEBh3G2D5g26rdeFWhgEDehGIiyV0gpQuJahSpB29HJkV1SFcCA56nTNhpevffPJWyqvAMJMDChqnwE43MV04dhD1pbpE1UAix4lk5S3jEumwTZ8uDItgVuXGktqlRZkG2hMSYihHrpJyJCD6TwvYzHyydq505cY8Nhrexl4vZVgT24EikGvL6CDFBoCLJUgB2tg7maRoSbxOKHgSi3Sw9YSXo0JHBpfq3IePjTPjlW4a7TFD0w4pplFjr1IQBejxNcxfwMtjz2WTq2CbFkf9n5fvpXjMU8EFXCw0ODqsoNyWAJ02T7rNCBJM7p69fViXT2AVb5Y39bKPOXUBpZxeeOpaMX1nw93lUwbuXkMemwPlJYtcEqANb"
key.chunked(500) {
write(it)
}
}
suspend fun write(key: CharSequence) {
// Write the key in order
}
ursus
11/20/2021, 3:55 PMinterface Id : Comparable<Id> {
val value: String
override fun compareTo(other: Id): Int = value.compareTo(other.value)
fun toString(): String = value
}
but it complains 'toString' hides member of supertype 'Comparable' and needs 'override' modifier
which is nonsense, but if I remove the comparable, then it complains that im hiding Any
is this possible?Jasin Colegrove
11/21/2021, 3:28 PMivan quintero
11/21/2021, 5:29 PMAhmed
11/22/2021, 10:36 AMplugins {
id("org.jetbrains.kotlin.jvm")
}
but for some reason, i am getting unresolved referenceJoshua Akinsola
11/22/2021, 12:15 PMpavi2410
11/22/2021, 1:52 PMURL.readText()
extension function from stdlib but for some unknown reason, it's not close
-ing the resources. However, the output is just printed fine at line 43igor.wojda
11/22/2021, 2:16 PMThe contents of a class should go in the following order:
Property declarations and initializer blocks
Secondary constructors
Method declarations
Companion object
What would be the reasoning of placing companion object at the end? (just personal style, or there is some actual argument behind it?)Marcin Wisniowski
11/22/2021, 2:41 PMdata class Point(val x: Int, val y: Int)
? In an API with lots of operations on such `Point`s, there is lots of Point
objects being created. Changing the API to operate on x and y parameters separately without a Point
class avoids the overhead, but makes the API less clean. Is there some language feature that can help here? I am looking for something like inline classes, but for two member properties.Dipendra Singh
11/22/2021, 3:46 PMval createEmail = {
if (type == Type.ERROR) {
dataProvider.createErrorEmail(id)
}
}
Michael de Kaste
11/23/2021, 11:06 AMinterface OpenRange<T : Comparable<T>> {
val start: T?
val endInclusive: T?
operator fun contains(value: T): Boolean = (
start?.let { value >= it }
?: true
) && (endInclusive?.let { value <= it } ?: true)
fun isEmpty(): Boolean = start != null && endInclusive != null && (start!! > endInclusive!!)
}
and then on something like
operator fun LocalDateTime.rangeTo(other: LocalDateTime?) = object : OpenRange<LocalDateTime> {
override val start: LocalDateTime = this@rangeTo
override val endInclusive: LocalDateTime? = other
}
But ofcourse, LocalDateTime already has an rangeTo, but yet, this compiles without trouble.
But when I call a localdatetime with the '..' operator now with a nullable other time, I get a type mismatch like the following.martmists
11/23/2021, 1:54 PMStewart Stewart
11/23/2021, 3:18 PMMarcin Wisniowski
11/23/2021, 11:35 PMRob Elliot
11/24/2021, 11:44 AMBufferedReader.forEachLine
doesn’t distinguish between last line\nEOF
and last lineEOF
- in both cases the last line emitted is last line
, whether it ends in a line feed or not.
This is frustrating if you need to capture the output of the Reader
exactly, but would also like to buffer based on line feeds rather than an arbitrary number of characters.
Anyone know of a workaround?
(It’s nearly NOT KOTLIN I know, because it just delegates to `java.io.BufferedReader.readLine`… hope the fact that kotlin has extension methods calling it justifies asking?!)igor.wojda
11/24/2021, 2:18 PMmutableListOf
) to create collections are quite handy, but I find them a bit painfull for testing:
class Bus {
private val persons = mutableSetOf<Person>()
fun addPerson(persons: Person) {
persons.add(person)
}
}
^ no easy way to test that person was added to the list.
We can always create a factory or pass in constructor, but I wonder how do you deal with that?
Is there anything better?ribesg
11/25/2021, 8:58 AMvalue class
? I just always name it value
and I wonder if there is another way that would make more senseursus
11/27/2021, 1:30 AMdata class PhoneNumber(val normalized: String)
and I need to format it with spaces etc before rendering in UI
Is this a member or extension function?MrHash
11/27/2021, 2:04 AMv79
11/29/2021, 8:33 AMclass Grid(val x:Int, val y: Int)
but in some cases there won't be a value. Rather than make it nullable, I'd like to be able to return something like Grid.NONE
instead. But not sure if this is a case for sealed classes, or interfaces, or an enum... I don't want to make Grid
open, and it's likely that Grid
will expand with additional properties and functions over time. Any suggestions?