Ian Lynagh
11/09/2021, 3:53 PM*.kt
files that form an application, and produce an equivalent single .kt
file?Ansh Tyagi
11/09/2021, 5:06 PMAyfri
11/09/2021, 10:27 PMeygraber
11/10/2021, 5:25 AMKenneth
11/10/2021, 2:28 PMNikolay Lebedev
11/10/2021, 7:53 PMRichard Gomez
11/10/2021, 8:49 PMRegex
vs. Java's Pattern
?Mo
11/11/2021, 2:48 AMErik Bender
11/11/2021, 8:14 AMByteArray
fun mapBytesToList(arr: ByteArray): List<T> {
if (arr.isEmpty()) {
return emptyList()
}
val bais = ByteArrayInputStream(arr)
var ois: ObjectInputStream? = null
return try {
ois = ObjectInputStream(bais)
ois.readObject() as List<T>
} catch (e: Exception) {
emptyList()
} finally {
try {
ois?.close()
} catch (e: Throwable) {
}
}
}
I get a UNCHECKED_CAST
warning at ois.readObject() as List<T>
. Do you have a hint on how to improve this function?Sivan
11/11/2021, 9:25 AMMarko Kunic
11/11/2021, 9:51 AMZode
11/11/2021, 9:56 AMFAILURE: Build failed with an exception.
* Where:
Build file '/Users/xxxx/Develop/kotlin/kotlin-native/build.gradle' line: 66
* What went wrong:
A problem occurred evaluating project ':kotlin-native'.
> Incorrect Xcode version: 13.1. Required major Xcode version is 12.
Guru
11/11/2021, 5:54 PMfun main() {
val callback = { i: Int, j: Int ->
val ii = i.times(j)
val jj = j.times(ii)
ii + jj
}
println(addAndMultiply(5, 6) { i, j ->
i + 1 + j
})
println(addAndMultiply(5, 6, callback))
}
inline fun <T> addAndMultiply(x: T, y: T, call: (T, T) -> T): T where T : Number {
if (x is BigDecimal || x is BigInteger) return call(x, y)
if (y is BigDecimal || y is BigInteger) return call(x, y)
return call(x, y) * x * y
}
I am getting reciever type mismatch at return call(x, y) * x * y
Any Idea ?martmists
11/11/2021, 7:24 PMorg.jetbrains.kotlin.backend.common.BackendException: Backend Internal error: Exception during IR lowering
Platform is JVM, and it seems like it has to do with my suspend functionsmartmists
11/12/2021, 1:58 AMval Extension.dispatcher by lazy {
SomeDispatcher()
}
Will the dispatcher
property be different for every Extension or will there be one global dispatcherSimon Lin
11/12/2021, 7:58 AMval deepList = listOf(
listOf(
listOf(-1, 0),
listOf(1)
),
listOf(2, 3),
listOf(4, 5, 6)
)
println(deepList.flatten()) // [-1, 0, 1, 2, 3, 4, 5, 6]
ex2:
val deepList = listOf(
-1,
listOf(listOf(listOf(0))),
listOf(2, 3),
listOf(4, 5, 6)
)
println(deepList.flatten()) // [-1, 0, 1, 2, 3, 4, 5, 6]
Pavel Repkin
11/12/2021, 11:21 AMMoritz Post
11/12/2021, 11:30 AMByteArray
? a direct conversion via byteArrayOf
does not work since the numbers are unsigned but ubyteArrayOf
does also not work for a reason i don't fully understand. It would be possible to map each number to it - 128
but that seams a bit unefficient. Help would be appreciated.Tomas Kormanak
11/12/2021, 12:13 PMwith
which is ignoring return value and returns Unit
?
Something like this:
public inline fun <T> with(receiver: T, block: T.() -> Unit): Unit {
receiver.block()
}
Or any better idea how to avoid explicitly returning Unit in this case:
fun process(data: Data) = with(data) {
///doSomething
Unit
}
Matias Reparaz
11/12/2021, 1:18 PMfun doSomething(param: SomeParams): Single<Something>
where Single is from RxJava. I want to use coroutines inside my implementation and wrap the value at the end. But how can I create the CoroutineContext? It’s ok to use the runBlocking in this context? something like this:
fun doSomething(param: SomeParams): Single<Something> = Single.just(
runBlocking {
doSomething()
}
)
suspend fun doSomething(): Something = TODO()
Thanksmcpiroman
11/13/2021, 11:58 AMval rng = Random(0)
generateSequence { rng.nextInt() }.take(10).toList()
Danny Morgan
11/13/2021, 12:41 PMdave08
11/14/2021, 10:57 AMclass Foo(val bar: Bar)
class Bar(val baz: String)
val foo = Foo(Bar("baz"))
// why isn't this possible?
val bazGetter = Foo::bar::baz
// whereas this is ok?
val bazGetter2: (Foo) -> String = { it.bar.baz }
reactormonk
11/15/2021, 11:52 AM@Inject
flying around? Or what's the usual way to extract parts of the codebase and sending a few arbitrary values through it for exploration purposes? I feel like I'm trying to fight the structure of the codebase here if I'm trying to construct everything manually.Mendess
11/15/2021, 12:10 PMfun foo() {
lateinit var x: Int
if (::x.isInitialized()) {}
}
This doesn't seem to workAyfri
11/15/2021, 2:45 PM1
and start always at the lower number, how can I do it in a simple way ?Bernhard
11/15/2021, 2:52 PMSteve Kim
11/15/2021, 4:58 PMeygraber
11/16/2021, 4:00 AMScanner(myFile).findAll(myPattern)
that returns a `Sequence<String>`(I know I can call asSequence
on the returned Stream
but I'm wondering if there's a specific Kotlin API for that)?ankushg
11/16/2021, 7:52 AM@Deprecated
A couple pain points that are popping up:
1. Deprecated code tends to call other deprecated code, and this generates too many warnings.
I currently have a ton of @Suppress("KotlinDeprecation", "DEPRECATION") @Deprecated
declarations all over my codebase, when there are only one or two actual places that are using the top-level, public Deprecated method.
2. Deprecations in import
statements are tricky.
When I intentionally use a deprecated declaration, I can @Suppress
it at the call site. But I can't @Suppress
the warning I get just for importing it!
For top-level declarations, I can use the fully-qualified name everywhere and just avoid importing the deprecated declaration. This doesn't work when you're using an extension function contained in an object
though.
Questions:
• Is there a way to automatically suppress Deprecation warnings within declarations that are also Deprecated?
• Is there a way to get the compiler to ignore when a @Deprecated
declaration is imported, but still warn when it is used?
• Or alternatively: is there a way I can use a fully-qualified name to avoid importing an extension function contained in an object
?