kevinherron
03/05/2021, 2:43 AMkotlin.Result
becomes usable as a return value in 1.5?knthmn
03/05/2021, 4:43 AMatomic<T>()
but Intellij cannot resolve it. What are those and where are they defined?Will Mwendwa
03/05/2021, 7:41 AMPriyank Jain
03/05/2021, 8:40 AMinline fun <reified O> getAPIResult(apiResponse: BaseResponseModel<O>): O? {
val actualResult: O? = try {
when (O::class.java) {
List::class.java -> {
apiResponse.getResponseModel(object : TypeToken<List<O>>() {}.type)
}
ArrayList::class.java -> {
apiResponse.getResponseModel(object : TypeToken<ArrayList<O>>() {}.type)
}
else -> {
apiResponse.getResponseModel(O::class.java)
}
}
} catch (e: Exception) {
null
}
return actualResult
}
Gopal S Akshintala
03/05/2021, 10:25 AMtypealias _Validator_<_ValidatableT_, _FailureT_> = _suspend_ (_ValidatableT_) -> _Either_<_FailureT_, Any?>
Within Kotlin, I use it like this as a data type to assign to a lamda val validateParent3X: _Validator_<_Egg_, _ValidationFailure_> = {...}
But I cannot use typealias from Java. What is the idiomatic way to use this Function type as data type on Java?
I see two unknows I have for java interoperability. 1. How can I idimotically refer a Function type 2. Function type being suspend
Andrew
03/05/2021, 10:26 AMfun Int.toFriendlyName(): String{
return when(this) {
PredefinedValue1 -> "PredefinedValue1"
PredefinedValue2 -> "PredefinedValue2"
PredefinedValue3 -> "PredefinedValue3"
else -> willNeverHappen("This value is not supported")
}
}
However this is problematic as this extension function can now be used on all integers in the scope of the extension functions.
I know that the `Int`s that I will be calling this on will be annotated with @Barcode.BarcodeFormat - so is there a way for me to mark that on my extension function so that I can only use it on integers with that specific annotation?jeggy
03/05/2021, 10:47 AMfun interface Ordering {
fun String.getOrdering(): List<String>
}
enum class CustomValueCriteriaOrder : Ordering {
ALPHABETICALLY {
override fun String.getOrdering(): List<String> {
return emptyList()
}
}
}
I could have
fun interface Ordering {
fun String.getOrdering(): List<String>
}
enum class CustomValueCriteriaOrder : Ordering {
ALPHABETICALLY { emptyList() }
}
nglauber
03/05/2021, 2:40 PMYan Pujante
03/05/2021, 5:49 PMkotlin.time.Duration
concept in my code and see that I can convert to String
pretty easily. I am not seeing a way to go the other way around, which makes it quite hard to use it as a field in a form or to save/retrieve in preferences... Am I missing something?Santosh Astagi
03/05/2021, 7:07 PMKush Patel
03/06/2021, 1:13 AMapply {}
does in order to understand the code. I am more curious to understand if there is some sort of tradeoff I’m missing here if one chooses A over B or vice versa. Thanks!
// A
val setOfInts = HashSet<Int>().apply{
for (i in 0..20) {
this += i
}
}
// B
val setOfInts = mutableSetOf<Int>()
for (i in 0..20) {
setOfInts.add(i)
}
Youssef Shoaib [MOD]
03/06/2021, 12:04 PM/*
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
so in this case should I change it to " Copyright 2010-2019 JetBrains s.r.o., Kotlin Programming Language contributors, and Firstname Lastname", or what should I do?Slackbot
03/06/2021, 8:49 PMtherealbluepandabear
03/07/2021, 3:58 AMfun charToNumber(input: Char): Int {
val numbersToLetters = listOf('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',
'T', 'U', 'V', 'W', 'X', 'Y', 'Z')
return numbersToLetters.indexOf(input.toUpperCase()) + 1
}
therealbluepandabear
03/07/2021, 4:15 AMfor (number in input.toString().split("")) {
}
123
03/07/2021, 12:16 PM.toString()
except overriding it? I have a LAZY collection in a data class, so it throws an exception on .toString()
Grigorii Yurkov
03/07/2021, 4:34 PMArray<Int>
and Array<in Int>
? In my opinion it should be Array<in Int>
. But kotlin compiler thinks it's Array<out Int?>
. I agree that Array<out Int?>
is supertype of both Array<Int>
and Array<in Int>
, but it's not the lowest. What do you think?therealbluepandabear
03/08/2021, 4:24 AMvineethraj49
03/08/2021, 4:45 AMtherealbluepandabear
03/08/2021, 7:33 AMkqr
03/08/2021, 8:21 AMRob Elliot
03/08/2021, 8:41 PMval xs = listOf("a", "e", "c", "b", "d")
xs.takeUntil { it == "c" } == listOf("a", "e", "c")
TwoClocks
03/08/2021, 10:26 PMval one = """text \$text"""
it won't escape the $. Works fine in a normal string. how do I turn of templating in raw strings?therealbluepandabear
03/09/2021, 12:22 AMtherealbluepandabear
03/09/2021, 1:21 AMJack Darlington
03/09/2021, 10:55 AMAness Iqbal
03/09/2021, 11:05 AMRob Elliot
03/09/2021, 11:37 AMsingleOrNull
- I assumed it would throw an exception if size > 1, but it returns null.Olivier Patry
03/09/2021, 2:23 PMpublic void setFoo(@NonNull Bar bar)
{
// ...
}
In Kotlin side
myObject.foo = null // OK
myObject.setFoo(null) // KO
The property access compiles 😱
The function call doesn't compile 👍
Is it expected?
Can I avoid exposing setFoo
as a Kotlin property at will?
It seems fragile to allow such property access, no?droid
03/09/2021, 3:17 PM