franztesca
10/13/2023, 10:34 AMasync/await
vs suspend
.
I was wondering if the main point of the comment was that suspend
is better because it's just composing a lazily evaluated function, vs async/await
being more like GlobalScope.launch { ... }.await()
, or if there is something more fundamental.
More specifically, looking at the async/await
of Swift, it seems pretty similar to suspend
(if not for ergonomics and syntax, where async/await
looks more monadic, and suspend
looks more like a co-effect), and they both enforce structured concurrency.
Does the argument of the tweet still apply for Swift, and, in that case, what is the main advantage of suspend
?
🤔Davio
10/14/2023, 9:51 AMvalue class MyInt(val value : Int)
val actualInt: Int = MyInt(1)
Sam Stone
10/16/2023, 5:32 PMopen class Parent(open val x: Int)
class Child(override val x: Int): Parent(x)
Instead of
open class Parent(open val x: Int)
class Child(override val x: Int): Parent()
Pablichjenkov
10/18/2023, 10:41 PMuses/inline/copy
::Fun2, ::Fun3
This kind of design. The result something like:
Fun1(){
Fun2()
Fun3()
...
}
Perhaps a feature in the Compose plugin 🤔stantronic
10/23/2023, 10:18 AMLocalTime.of(10,05)
reads a bit more naturally than LocalTime.of(10,5)
andrzej
10/26/2023, 3:07 PMnull
without any additional burden, smth. like tapNone
in arrow.
Now I have to do the following:
someComplicatedComputation()
?: run {
println("We got null")
null
}
while for Option type in arrow I have much simpler and more readable:
someComplicatedComputation()
.tapNone {
println("We got null")
}
or did I overlook something from the standard lib?eygraber
11/23/2023, 2:13 AMtoSet
and toMutableSet
different? Can't they both use LinkedHashSet(this)
(which seems to be more performant)?zokipirlo
11/24/2023, 10:26 AMSealedClass.InnerClass
syntax?
For example:
sealed class Message(val...) {
class Text(...) : Message(...) {
...
}
class Image(...) : Message(...) {
...
}
}
when (message) {
is Message.Text -> ...
is Message.Image -> ...
}
fun someFun(val msg: Message.Text) {}
But if I extract Text
and Image
to separete file from Message
class file, because that file can be easiliy thounds of lines of code long, it would become:
when (message) {
is Text -> ...
is Image -> ...
}
fun someFun(val msg: Text) {}
And when using those classes all around a project you lose hierarchy that Text
is part of Message
. I think it's still more pretty to use Message.Text
. Could be possible somehow to combine best of both worlds?eygraber
11/26/2023, 6:29 PMfun handleClicks(
onClick: () -> Unit,
onLongClick: () -> Unit
)
loses context when called like
handleClicks(
onClick = {...}
) {
...
}
Davio
11/30/2023, 8:42 AMmap
and flatMap
? Currently map
on Iterable always returns a List<T>
, but what if you applied map to a set and wanted a set as a result? There is mapTo
, but it is a bit cumbersome to use. What about mapToSet
or something? Then you could also have a proper initial size for the backing setdiego-gomez-olvera
11/30/2023, 10:27 AMBen Woodworth
12/01/2023, 3:38 PMfun interface
lambdas still need the explicit interface name? (as opposed to function calls, where it's not required)
https://youtrack.jetbrains.com/issue/KT-14151 (which hasn't gotten much love)
In a library of mine I'm changing a function with a few SAM lambda parameters into a builder DSL, and it feels weird/unfortunate that the explicit type would now be requiredarshadm
12/07/2023, 4:15 PMYoussef Shoaib [MOD]
12/08/2023, 1:41 PMAlejandro Serrano.Mena
12/22/2023, 1:05 PMSzymon Jeziorski
12/29/2023, 9:07 AMlist: List<T>
you can call list.removeFirst()
, or list.removeLast()
just as if you were calling MutableList<T>.removeFirst()
, or MutableList<T>.removeLast()
extensions. Similarly, addFirst/Last
methods are also visible
To me this sounds problematic for 2 main reasons:
• one might confuse the type being worked on - you wouldn't normally see mutating methods in autocomplete for objects exposed via read-only interfaces, so I can imagine someone mutating a collection by accident (especially by confusing with a well-known removeFirst/Last extension with the same name as the new interface's methods)
• just as in Java's world, the result of the operation depends on the underlying implementation, meaning you have to watch out for UnsupportedOperationException
againeygraber
01/07/2024, 10:33 PM@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
will ever stop working for accessing internal
members of another module?Marcin Wisniowski
01/12/2024, 5:34 PMDavid Kubecka
01/18/2024, 10:56 AM@OverloadResolutionByLambdaReturnType
annotation. So while this works as expected (prints 0
)
@OptIn(ExperimentalTypeInference::class)
@OverloadResolutionByLambdaReturnType
fun test(a: () -> Int) = a() + 1
@OptIn(ExperimentalTypeInference::class)
@OverloadResolutionByLambdaReturnType
fun test(a: () -> String) = a()
test { "0" }
changing the signature of the second overload to fun test(a: () -> Any)
makes the code no longer compiling (with type mismatch error) . Is this something which can be potentially fixed?Dave
01/31/2024, 9:56 AMUsing enum classes with anWhat is the future plan for interop with externally defined Enums ?qualifier becomes deprecated and will be an error in future releasesexternal
Kev
02/01/2024, 4:34 AMAlejandro Serrano.Mena
02/07/2024, 10:51 AMwhen
expressions -> https://github.com/Kotlin/KEEP/issues/371Youssef Shoaib [MOD]
02/10/2024, 11:34 AM@JvmInline value class PartiallyProcessedResult<T>(val result: Result<T>)
inline infix fun <T, R> Result<T>.myFold(ifSuccessful: (T) -> R): PartiallyProcessedResult<R> = PartiallyProcessedResult(map(ifSuccessful))
inline infix fun <R> PartiallyProcessedResult<R>.ifThrowable(ifThrowable: (Throwable) -> R): R = result.getOrElse(ifThrowable)
// allows
result myFold { ... } ifFailure { ... }
This example is easier to figure out than other more-complex use cases (e.g. if both lambdas need to be available at the same time, then there's no option to inline
, and instead one must pass lambdas around).
This would also allow some nice SQL-like DSLs
EDIT: removed bad initial suggestion of multiple lambdas with no infix in the middlestantronic
02/12/2024, 11:59 AMfun myProductionFun(){ ... }
@TestSource
fun testMyProductionFun(){ ... }
stantronic
02/13/2024, 6:44 PMansman
02/15/2024, 2:31 PMclass C {
val a = 1
}
context(C)
fun foo() {
a // Works
this@C // Works
this@C.a // Works
}
val lambda: context(C) () -> Unit = {
a // Works
this@C // Does not work
this@C.a // Does not work
}
eygraber
02/19/2024, 8:49 PMRob Elliot
02/21/2024, 10:29 AMbar*.foo()
dereference operator to mean bar.map { it.foo() }
and possibly a bar**.foo()
to mean bar.flatMap { it.foo() }
, in the same way that we have bar?.foo()
to mean if (bar == null) null else bar.foo()
.Youssef Shoaib [MOD]
02/22/2024, 12:41 PMoperator fun componentN(i: Int)
that would generalise component1
, component2
etc? Or perhaps get
should serve that purpose if it has one Int
argumenteygraber
02/22/2024, 4:42 PM