Animesh Sahu
11/14/2020, 5:05 AMEdoardo Luppi
11/14/2020, 5:29 PMvar n = completionProviders.indexOfFirst(...) + 1
if (n == 0) {
n = completionProviders.size
}
Not with takeUnless/takeIfNikky
11/15/2020, 11:40 AMget
.. would avoid some ugly hacks with let
or assigning intermediary variables
not sure if that would promote writing worse code and longer nullsafe call chains..ciscorucinski
11/15/2020, 2:12 PMfun sayHello(greeting: String, vararg names: String) {
names.forEach { name ->
println("$greeting $name")
}
}
fun main() {
val interestingThings3 = arrayOf("Kotlin", "Programming", "Coding")
sayHello(greeting = "Hi", *interestingThings3)
sayHello(greeting = "Hi", names = *interestingThings3)
}
This works, but the last statement suggests to remove Redundant spread (*) operator
. That leads to the following valid code.
fun main() {
val interestingThings3 = arrayOf("Kotlin", "Programming", "Coding")
sayHello(greeting = "Hi", *interestingThings3)
sayHello(greeting = "Hi", names = interestingThings3)
}
Since the last statement doesn't need the spread operator, I thought I would remove it from both
fun main() {
val interestingThings3 = arrayOf("Kotlin", "Programming", "Coding")
sayHello(greeting = "Hi", interestingThings3) // ERROR
sayHello(greeting = "Hi", names = interestingThings3)
}
But this gives an error on the first statement.
Why? Why does the first one error out, but the last one if perfectly fine.william
11/15/2020, 5:28 PMsealed class BinaryTree<T> {
val root: BinaryTree<T> = Leaf
}
data class Node<T>(val data: T, val left: BinaryTree<T>, val right: BinaryTree<T>) : BinaryTree<T>()
object Leaf : BinaryTree<Nothing>()
can anyone help my understand why root: BinaryTree<T> = Leaf
gives the error
Type mismatch.
Required:
BinaryTree<T>
Found:
Leaf
Florian
11/15/2020, 7:05 PMval searchQuery = state.getLiveData("query", "")
private val tasksFlow = combine(
searchQuery.asFlow(),
preferencesFlow
) { query: String, filterPreferences: FilterPreferences ->
Pair(query, filterPreferences)
}.flatMapLatest { (query, filterPreferences) ->
taskDao.getTasks(query, filterPreferences.sortOrder, filterPreferences.hideCompleted)
}
If I set searchQuery.value = null
this will crash. How can I get null-safety here?zero_coding
11/15/2020, 9:00 PMNuru
11/16/2020, 9:46 AMAnimesh Sahu
11/16/2020, 10:26 AMEdoardo Luppi
11/16/2020, 2:33 PMuser
11/16/2020, 3:03 PMIaroslav Postovalov
11/16/2020, 3:35 PMpublic operator fun T.minus(b: T): T = add(this, -b)
ribesg
11/16/2020, 3:56 PMthana
11/16/2020, 7:13 PMOutOfMemoryException
during compileKotlinJs
. Any idea how to tackle that?Alberto
11/17/2020, 4:29 AMget()
method (non-suspend) and a getAsync()
method (suspendable), which one should own the logic/implementation?
Option 1 (suspendable owns the logic/implementation):
fun get(): String {
return runBlocking {
getAsync()
}
}
suspend fun getAsync(): String {
// actual getter logic
}
Option 2 (non-suspendable owns the logic/implementation):
fun get(): String {
// actual getter logic
}
suspend fun getAsync(): String {
withContext(dispatchers.default()) {
return get()
}
}
hhariri
11/17/2020, 8:15 AMBjörn Mayer
11/17/2020, 10:12 AMfun interface PropHandler<P> {
fun P.handle(): Unit
}
Andrea Giuliano
11/17/2020, 11:53 AMelect
11/17/2020, 2:36 PMDan Newton
11/17/2020, 4:10 PMbbaldino
11/17/2020, 6:10 PMRuntime JAR files in the classpath should have the same version
. Is it possible to depend on a 1.3 lib in a 1.4 project? Should I be setting the kotlin-stdlib dependencies in the 1.3 project to compile
scope or something?Slackbot
11/17/2020, 6:28 PMdMusicb
11/17/2020, 6:32 PMencodeToString("${long1}${long2}".toByteArray())
?robstoll
11/17/2020, 8:07 PMfun <reified T>
is a nullable type? I am asking in the context of https://youtrack.jetbrains.com/issue/KT-8947
I would like to be able to do something like:
fun <reified T> foo() = if(T::isNullable) "y" else "n"
foo<Int?>() // returns y
foo<Int>() // return n
Hanno
11/17/2020, 8:55 PMSourabh Rawat
11/18/2020, 5:40 AMNathan Retta
11/18/2020, 6:22 AMinline fun <reified T> HashMap<String, T>.toAnalyticsBundle(): Bundle {
val analyticsRegex = Regex(FirebaseAnalyticsManager.ANALYTICS_REGEX_STRING)
return Bundle().apply {
for (key in keys) {
val value = this@toAnalyticsBundle[key]
val firebaseKey = FirebaseAnalyticsManager.googleAnalyticsifyString(key, analyticsRegex)
when (value) {
is Int -> this@apply.putInt(firebaseKey, value)
is Float -> this@apply.putFloat(firebaseKey, value)
is Double -> this@apply.putDouble(firebaseKey, value)
is Boolean -> this@apply.putBoolean(firebaseKey, value)
is Char -> this@apply.putChar(firebaseKey, value)
is String -> this@apply.putString(firebaseKey, value)
is Parcelable -> this@apply.putParcelable(firebaseKey, value)
is Serializable -> this@apply.putSerializable(firebaseKey, value)
}
}
}
}
fun googleAnalyticsifyString(stringToConvert: String, regex: Regex = Regex(ANALYTICS_REGEX_STRING)): String {
val charArray = stringToConvert.toLowerCase().replace(regex, "").toCharArray()
for((index, char) in charArray.withIndex()) {
if(char == ' ') {
val nextCharIndex = index + 1
if(nextCharIndex < stringToConvert.length) {
charArray[nextCharIndex] = charArray[nextCharIndex].toUpperCase()
}
}
}
return charArray
.joinToString("")
.replace(" ", "")
}
Bernhard
11/18/2020, 11:54 AMribesg
11/18/2020, 2:49 PMCicero
11/18/2020, 8:38 PMCicero
11/18/2020, 8:38 PMredenergy
11/18/2020, 8:54 PMCicero
11/18/2020, 9:01 PM