Slackbot
07/01/2021, 12:53 AMTomasz Krakowiak
07/01/2021, 6:12 PMhfhbd
07/19/2021, 11:03 AMInt/Double/String/LiteralExpression
feature to Kotlin? Ideally, this would be an interface, maybe even restricted to the compiler only. This would allow you to limit some helper functions to literals only, and don't pollute the namespace with helper methods.
Sample
val IntLiteral.seconds: Duration get() = ...
fun getX() = 42
val secs = 2.seconds // valid, as 2 is a constant literal
val secs2 = getX().seconds //invalid, seconds can only be called from a IntLiteral
Swifts similar implementation: https://developer.apple.com/documentation/swift/swift_standard_library/initialization_with_literalslouiscad
07/20/2021, 3:18 PMStuff.kt
that'd default to commonMain
, Stuff.js.kt
in the main
directory that'd be part of the jsMain
sourceSet, TestWhatever.js.kt
in the test
directory would be part of the jsTest
sourceSet, and Stuff.darwin.kt
in the main
directory would be part of the custom darwinMain
sourceSet.
That also makes me think about how .main.kts
, .gradle.kts
and .whatever.kts
files all resolve different symbols based on their extension.denis.zharkov
08/11/2021, 3:27 PMT!!
syntax to a limited version of intersection types – T & Any
.
It’s likely that at some point we’ll have full support for intersection types and then it would be just a special case that doesn’t deserve special syntax because it seems that the only real-world use-case we have by now is overrides of annotated Java.simon.vergauwen
08/16/2021, 6:41 PM() -> A
where suspend () -> A
is expected.simon.vergauwen
08/16/2021, 6:41 PMDavid Gracia
08/28/2021, 11:40 PMpablisco
09/01/2021, 8:33 AMEmil Kantis
09/07/2021, 9:30 PMtrySingle
for collections) would be useful as part of the stdlib? Or have any alternate solutions? 🙂
fun doSomething(customerId: Int) {
val user = when (val result = fetchExistingUsers().trySingle { it.id == customerId }) {
is MultipleFound -> error("Duplicate users for single ID")
is NoneFound -> createUser()
is Single -> result.single
}
}
Ruckus
09/09/2021, 2:42 PMEndre Deak
09/24/2021, 8:50 PM// delegation as of now:
interface A { fun foo() }
interface B { fun bar() }
class AImpl() : A { override fun foo() = println("default foo") }
class BImpl(private val a: AImpl) : B, A by a { override fun bar() = println("bar") }
// delegation after proposal:
interface A { fun foo() }
interface B : A { fun bar() }
class AImpl() : A { override fun foo() = println("default foo") }
class BImpl(private val a: AImpl) : B by a { override fun bar() = println("bar") }
Hope this makes sense. The benefit is that BImpl
does not have to explicitly rely on interface A
.Ruckus
09/28/2021, 6:43 PM.=
operator
I'm not sure if this use case will be covered by the deep immutability enhancements that have been mentioned.
The new operator would serve the same purpose to the dot operator that you get with appending =
to other operators (e.g. +=
, /=
, etc.)
Basically, allow replacing things like position = position.copy(y = 10)
with position.=copy(y = 10)
Javier
10/12/2021, 10:24 AMfun String.remove(value: String): String = replace(value, "")
Klitos Kyriacou
10/13/2021, 8:57 PMfun foo(a: Int, b: Long, c: Double)
and a variable of type RequestBody
data class RequestBody(val a: Int, val b: Long, val c: Double)
and I call it like this:
foo(requestBody.a, requestBody.b, requestBody.c)
It would be nice if the spread operator worked on these arguments (not just varargs) so that I could do this:
foo(*requestBody)
Or is there some existing way that this can be done in a succinct way?Nathan Bedell
10/15/2021, 1:57 PMclass MyGenericClass<interface I: SomeInterface>(): I {...}
Essentially, allowing us to declare a generic type I as an interface -- this allowing classes or other interfaces in the scope of the type parameter I to inherit from I.
I've run into a few circumstances where I find myself wanting something like this -- e.x. when I depend on a generic interface, and then I want a class to extend that interface so that within the class I can access that interface's methods/properties directly, rather than by referencing the interface itself, e.x:
class MyView<interface I: IMyViewModel>(val vm: I): I by vm { ... }
"View" here (Maybe not the best word) being in a general sense, not an Android View -- something that subscribes to the view model events, and updates the UI accordingly.LastExceed
10/30/2021, 8:01 AMlateinit
for properties of non-primitive inline/value types
@JvmInline
value class Id(val value: String)
class MyClass {
lateinit var id1: String //this is fine
lateinit var id2: Id //so this should be too
}
Rob Elliot
11/03/2021, 11:16 AMeduardog3000
11/03/2021, 6:51 PM??=
operator. You can read about it here on MDN. Based on this I'd like to restart discussion of the idea for Kotlin. It would function pretty much exactly as the MDN page describes.Scott Christopher
11/04/2021, 10:31 PMScott Christopher
11/16/2021, 11:27 AMsealed class Foo<T> {
object FooBool : Foo<Boolean>()
object FooInt : Foo<Int>()
}
fun <T> match(x: Foo<T>): T = when (x) {
is Foo.FooBool -> true
is Foo.FooInt -> 42
}
Miguel Vargas
11/18/2021, 8:05 PMpackage a
class B {
// only accessible from within this file
file-private val priv = 123
}
fun c(b: B) {
println("I can access ${b.priv}")
}
joseph_ivie
11/22/2021, 10:29 PMfun example() {
wrapped with with(SomeDSL)
dslCall()
}
desugars to:
fun example() {
with(SomeDsl) {
dslCall()
}
}
Michael Böiers
12/02/2021, 10:00 PMMutablePerson
, and it would then automatically have a method toPerson(): Person
.edrd
12/03/2021, 4:40 PMconst val
will never change. An enum member will never change. There's nothing to pay more attention here than any other symbol (maybe it should actually be the opposite, a top-level var
should have this convention because that can lead to issues -- although I think in this case it should also be prefixed with CODESMELL_
😁).
My guess is this convention came from Java, which came from C/C++, where developers reading macro usages should immediately know it would expand to arbitrary code, but this is not the case in Kotlin.Alejandro Serrano Mena
12/06/2021, 8:52 PMis
tests in Kotlin by adding some lightweight type refinement on matching; this is what I came up with https://gist.github.com/serras/ee07f36b38756f076d654496a3d2eb61
I would love to know what the community thinks about it; it seems waaay more simple than what Scala does, but it still unlocks quite some power in the type checkerMichael de Kaste
12/07/2021, 8:57 PMsealed fun interface
will be added in the future?jimn
12/10/2021, 2:24 PMhenrik
12/14/2021, 12:25 PMconst val arrayLiteral = ["books", "default"]
could then be used in an annotation like @CacheConfig(cacheNames = arrayLiteral)
.ephemient
12/18/2021, 9:36 PMfun <T> MutableList<T>.splice(indices: IntRange, values: Iterable<T>)
? name debatable but that's what as Javascript, Perl, and Rust name the same function, and it's easily accessible via list[start..end] = values
in Python and Rubyephemient
12/18/2021, 9:36 PMfun <T> MutableList<T>.splice(indices: IntRange, values: Iterable<T>)
? name debatable but that's what as Javascript, Perl, and Rust name the same function, and it's easily accessible via list[start..end] = values
in Python and Rubyfun <T> MutableList<T>.splice(indices: IntRange, values: Iterable<T>) {
var rangeSize = indices.endInclusive - indices.start + 1
var count = 0
var iterator = values.iterator()
while (count < rangeSize && iterator.hasNext()) {
this[indices.start + count++] = iterator.next()
}
if (count < rangeSize) {
subList(indices.start + count, indices.endInclusive + 1).clear()
} else if (values is List) {
addAll(indices.start + count, values.drop(count))
} else {
while (iterator.hasNext()) {
add(indices.start + count++, iterator.next())
}
}
}
but haven't really exercised it yetlouiscad
12/19/2021, 12:49 AMephemient
12/19/2021, 12:50 AM: Unit
return type is implied for { }
block defined functions.subList(indices).toList()
first if that's what they want, but it's commonly used enough to warrant being built in here IMOedrd
12/19/2021, 8:48 PMoperator fun <T> MutableList<T>.set(indices: IntRange, values: Iterable<T>)
louiscad
12/19/2021, 11:38 PMmcpiroman
12/20/2021, 10:06 AMval a = list[2..5]
? I guess maybe it's difficult to choose whether it should be an alias for `subList`vs slice
.