darkmoon_uk
11/22/2019, 1:27 AMoverride var customText6: String? = null public get() {
return field
}
...is this ☝️ backed by a variable or computed? 🤦Mike
11/22/2019, 2:04 AMdf
11/22/2019, 9:50 AMAdriano Celentano
11/22/2019, 10:47 AMdata class Document(val uri: Uri)
data class ValidatedDocument(val uri: Uri)
fun validateDocument(document: Document): ValidatedDocument {
val valid = true
if(valid) {
return ValidatedDocument(documentUpload.uri)
} else {
throw IllegalArgumentException("not valid")
}
}
fun uploadDocument(validatedDocument: ValidatedDocument) {
}
fun main() {
val doc = Document(uri = Uri.EMPTY)
val validDoc = validateDocument(doc)
uploadDocument(validDoc)
}
Robert Jaros
11/22/2019, 11:29 AMString
or String?
as a parameter and returns simple String
when called with String
or nullable String?
when called with String?
?Yekta
11/22/2019, 12:11 PMYekta
11/22/2019, 12:12 PMDaniele Segato
11/22/2019, 12:32 PMdata class
can't be extended (ok).
If I chose to use an interface
and implement it with a data class
I can do things like this
interface MyPublicInterface {
val x: String
val y: Int
val z: Whatever
}
data class MyImplementation(
override val x: String,
override val y: Int,
override val z: Whatever
): MyPublicInterface
now this is ok, but if I do this then I can't use the useful copy()
or componentN()
functions method that comes along with a data class on my interface without casting it to my implementation.
Is there some way to make my interface declare the copy()
and componentN()
?
for the componentN()
I guess it's possible by just defining the operators, but then I'd had to manually maintain them, still ok. But for copy()
I've no idea how to do itelect
11/22/2019, 1:05 PM@JvmName
a custom getter extender? (val Bar.foo get() =..
)Sam Garfinkel
11/22/2019, 6:44 PMval inner = """
- List Entry 1
- List Entry 2
""".trimIndent()
val outer = """
Outer:
$inner
""".trimIndent()
fun main() {
println(outer)
}
What I get:
Outer:
- List Entry 1
- List Entry 2
What I want (expect):
Outer:
- List Entry 1
- List Entry 2
igor.wojda
11/22/2019, 9:47 PMCyberpunk Keanu
11/23/2019, 1:40 PMmending3
11/23/2019, 3:59 PM$arr = [
[
"name" => "john"
],
[
"name" => "michael"
]
];
how do I achieve the above?farzad
11/24/2019, 8:23 AMdata class RequestModel(
val description: String?
)
and a validation function
fun validate(model: RequestModel): RequestModel{
if(model.description == null) throw IllegalArgumentException("description must be non null")
return model
}
After this validation step, I need a way to indicate non-nullability of description
property.
One solution is to create a new data class which has non null propertis data class RequestModel(val description: String)
.
But I'm looking for a generic way to avoid creating new classes per use case.
Ideal generic solution:
fun validate(model: RequestModel): NoNullableField<RequestModel>
How can I remove nullability from properties of a c.lass with nullable properties in a generic way? Is it usefull to use some kind of kotlin compiler contract?
Link to SO question: https://stackoverflow.com/questions/59015821Madalin Valceleanu
11/24/2019, 11:23 AMrobstoll
11/24/2019, 1:22 PM/
in a function name? e.g. `fun `/`` is not allowed but `fun `+`` isAnthony Styzhin
11/24/2019, 5:33 PMfun findShort(s: String): Int = s.split(" ").minBy { it.length }!!.count()
vs
fun findShort(s: String): Int = s.split(" ").minBy { it.length }!!.length
Both options work, pass unit tests and both are presented among solutions at codewars. Just trying to satisfy my curiosity ^^
Thanks in advance!karelpeeters
11/24/2019, 6:21 PMbar
here?
inline fun <reified A: Any?> foo() {
bar(A::class)
}
fun <B: Any> bar(cls: KClass<B>) {}
This should be possible, A::class
always returns the proper class, even if A
is nullable. It looks like the compiler doesn't realize that (I'll probably report this on youtrack). Usually I'd just cast something but I'm not sure how to do that here, I want to cast to A!!
but that's not real syntax of course. Any tricks?Nimelrian
11/25/2019, 10:11 AMval inputSet = createInputSet(path, month, year, currentTimestamp)
val parser = BatchingDeclineRateFileParser(batchingConfiguration.batchSize, path)
return generateSequence { parser.parseBatch() }
.map { batch ->
val updatedInputSet = updateBatchedInputSet(inputSet, batch)
transactionManager.runInTransaction {
rateInputRepository.createAll(batch.batchItems, month, year, updatedInputSet.id)
inputSetRepository.updateBatchStep(updatedInputSet)
}
updatedInputSet
}
.find { it.isProcessingDone } ?: throw JobException("Batch did not complete for some reason")
This works in general, but due to using map I only update the original input set each time.
Is there a function on Sequence
which works like e.g. ReactiveX's scan
where I can fold the incoming values into an accumulator? http://reactivex.io/documentation/operators/scan.htmlrikusen0335
11/25/2019, 10:38 AMjava.lang.NoClassDefFoundError: org/jetbrains/exposed/sql/Database
.Stephan Schroeder
11/25/2019, 11:10 AM[Returns(true) -> x is String]
fun isString(x: Any?): Boolean = x is String
so I was interested in seeing if I can write a reified generic version (https://pl.kotl.in/XNSuwtkvC, which would be pretty useful for custom equals-methods):
inline fun <reified T:Any> T.hasSameClass(other: Any?): Boolean {
contract {
returns(true) implies (other is T)
}
if (this === other) return true
return other!=null && this.javaClass == other.javaClass
}
Unfortunately currently this fails due to “references to type parameters are forbidden in contracts”. References to reified type parameters should be doable (<- my feature request).yayabobi
11/25/2019, 12:51 PMtapchicoma
11/25/2019, 8:36 PMpablofloresarg
11/25/2019, 9:01 PMjames
11/26/2019, 12:31 AMcanEditProfile
and the java class has a field named isCanEditProfile
. I'll have a new kotlin class which exposes a few of these fields, and I think the name isCanEditProfile
seems a bit odd, so I'm looking for alternatives for this and a few other similar booleans.
I know is*
and has*
are commonly accepted boolean prefixes in the java/kotlin world, I'm just wondering if can*
is also acceptable in this context?Joey
11/26/2019, 3:01 AMCan
11/26/2019, 9:51 AM./gradlew clean lintDebug
sometimes include my custom checks and sometimes they do not. Same with Android Studio (inspections in the file are sometimes visible, sometimes they are not). I am having these issues in a rather large project - the same problems are not visible in an equivalent test-project.
What should be the steps to see custom lint rules in action? Should just performing ./gradlew clean lintDebug
lead to the result we wish?Gyuhyeon
11/26/2019, 9:53 AM// autoconverted from java
@Transactional
fun leaveMembership(membershipNo: Long): Boolean {
val membership = repository.selectOne(membershipNo) ?: return false
membershipDeletedService.insertExpireHistory(membership)
repository.delete(membershipNo)
return true
}
// futile attempt to use as much kotlin stuff
@Transactional
fun leaveMembership(membershipNo: Long): Boolean = repository.selectOne(membershipNo)?.let {
membershipDeletedService.insertExpireHistory(it)
repository.delete(membershipNo)
true
} ?: false
Which is more "kotlin-esque"? Or rather, which code do you think is better? If both are bad, how can it be refactored?Xabier Gorostidi
11/26/2019, 10:06 AMNSInvalidArgumentException', reason: '*** -getValue: only defined for abstract class. Define -[KotlinInt getValue:]!
error when using a Kotlin/Nativei library from Swift?
fun testMap(): Map<Int, Int> {
return mutableMapOf(
Pair(0, 1))
}
kartikpatodi
11/26/2019, 10:36 AM"
or comments ?
I need it as utility that searches for a text or pattern in kt files but not if it is inside string literal or comments.kartikpatodi
11/26/2019, 10:36 AM"
or comments ?
I need it as utility that searches for a text or pattern in kt files but not if it is inside string literal or comments.diesieben07
11/26/2019, 10:39 AMkartikpatodi
11/26/2019, 11:07 AMdiesieben07
11/26/2019, 11:09 AMMatteo Mirk
11/26/2019, 6:24 PM