https://kotlinlang.org logo
Join the conversationJoin Slack
Channels
100daysofcode
100daysofkotlin
100daysofkotlin-2021
advent-of-code
aem
ai
alexa
algeria
algolialibraries
amsterdam
android
android-architecture
android-databinding
android-studio
androidgithubprojects
androidthings
androidx
androidx-xprocessing
anime
anko
announcements
apollo-kotlin
appintro
arabic
argentina
arkenv
arksemdevteam
armenia
arrow
arrow-contributors
arrow-meta
ass
atlanta
atm17
atrium
austin
australia
austria
awesome-kotlin
ballast
bangladesh
barcelona
bayarea
bazel
beepiz-libraries
belgium
berlin
big-data
books
boston
brazil
brikk
budapest
build
build-tools
bulgaria
bydgoszcz
cambodia
canada
carrat
carrat-dev
carrat-feed
chicago
chile
china
chucker
cincinnati-user-group
cli
clikt
cloudfoundry
cn
cobalt
code-coverage
codeforces
codemash-precompiler
codereview
codingame
codingconventions
coimbatore
collaborations
colombia
colorado
communities
competitive-programming
competitivecoding
compiler
compose
compose-android
compose-desktop
compose-hiring
compose-ios
compose-mp
compose-ui-showcase
compose-wear
compose-web
connect-audit-events
corda
cork
coroutines
couchbase
coursera
croatia
cryptography
cscenter-course-2016
cucumber-bdd
cyprus
czech
dagger
data2viz
databinding
datascience
dckotlin
debugging
decompose
decouple
denmark
deprecated
detekt
detekt-hint
dev-core
dfw
docs-revamped
dokka
domain-driven-design
doodle
dsl
dublin
dutch
eap
eclipse
ecuador
edinburgh
education
effective-kotlin
effectivekotlin
emacs
embedded-kotlin
estatik
event21-community-content
events
exposed
failgood
fb-internal-demo
feed
firebase
flow
fluid-libraries
forkhandles
forum
fosdem
fp-in-kotlin
framework-elide
freenode
french
fritz2
fuchsia
functional
funktionale
gamedev
ge-kotlin
general-advice
georgia
geospatial
german-lang
getting-started
github-workflows-kt
glance
godot-kotlin
google-io
gradle
graphic
graphkool
graphql
graphql-kotlin
graviton-browser
greece
grpc
gsoc
gui
hackathons
hacktoberfest
hamburg
hamkrest
helios
helsinki
hexagon
hibernate
hikari-cp
hire-me
hiring
hongkong
hoplite
http4k
hungary
hyderabad
image-processing
india
indonesia
inkremental
intellij
intellij-plugins
intellij-tricks
internships
introduce-yourself
io
ios
iran
israel
istanbulcoders
italian
jackson-kotlin
jadx
japanese
jasync-sql
java-to-kotlin-refactoring
javadevelopers
javafx
javalin
javascript
jdbi
jhipster-kotlin
jobsworldwide
jpa
jshdq
juul-libraries
jvm-ir-backend-feedback
jxadapter
k2-early-adopters
kaal
kafka
kakao
kalasim
kapt
karachi
karg
karlsruhe
kash_shell
kaskade
kbuild
kdbc
kgen-doc-tools
kgraphql
kinta
klaxon
klock
kloudformation
kmdc
kmm-español
kmongo
knbt
knote
koalaql
koans
kobalt
kobweb
kodein
kodex
kohesive
koin
koin-dev
komapper
kondor-json
kong
kontent
kontributors
korau
korean
korge
korim
korio
korlibs
korte
kotest
kotest-contributors
kotless
kotlick
kotlin-asia
kotlin-beam
kotlin-by-example
kotlin-csv
kotlin-data-storage
kotlin-foundation
kotlin-fuel
kotlin-in-action
kotlin-inject
kotlin-latam
kotlin-logging
kotlin-multiplatform-contest
kotlin-mumbai
kotlin-native
kotlin-pakistan
kotlin-plugin
kotlin-pune
kotlin-roadmap
kotlin-samples
kotlin-sap
kotlin-serbia
kotlin-spark
kotlin-szeged
kotlin-website
kotlinacademy
kotlinbot
kotlinconf
kotlindl
kotlinforbeginners
kotlingforbeginners
kotlinlondon
kotlinmad
kotlinprogrammers
kotlinsu
kotlintest
kotlintest-devs
kotlintlv
kotlinultimatechallenge
kotlinx-datetime
kotlinx-files
kotlinx-html
kotrix
kotson
kovenant
kprompt
kraph
krawler
kroto-plus
ksp
ktcc
ktfmt
ktlint
ktor
ktp
kubed
kug-leads
kug-torino
kvision
kweb
lambdaworld_cadiz
lanark
language-evolution
language-proposals
latvia
leakcanary
leedskotlinusergroup
lets-have-fun
libgdx
libkgd
library-development
linkeddata
lithuania
london
losangeles
lottie
love
lychee
macedonia
machinelearningbawas
madrid
malaysia
mathematics
meetkotlin
memes
meta
metro-detroit
mexico
miami
micronaut
minnesota
minutest
mirror
mockk
moko
moldova
monsterpuzzle
montreal
moonbean
morocco
motionlayout
mpapt
mu
multiplatform
mumbai
munich
mvikotlin
mvrx
myndocs-oauth2-server
naming
navigation-architecture-component
nepal
new-mexico
new-zealand
newname
nigeria
nodejs
norway
npm-publish
nyc
oceania
ohio-kotlin-users
oldenburg
oolong
opensource
orbit-mvi
osgi
otpisani
package-search
pakistan
panamá
pattern-matching
pbandk
pdx
peru
philippines
phoenix
pinoy
pocketgitclient
polish
popkorn
portugal
practical-functional-programming
proguard
prozis-android-backup
pyhsikal
python
python-contributors
quasar
random
re
react
reaktive
realm
realworldkotlin
reductor
reduks
redux
redux-kotlin
refactoring-to-kotlin
reflect
refreshversions
reports
result
rethink
revolver
rhein-main
rocksdb
romania
room
rpi-pico
rsocket
russian
russian_feed
russian-kotlinasfirst
rx
rxjava
san-diego
science
scotland
scrcast
scrimage
script
scripting
seattle
serialization
server
sg-user-group
singapore
skia-wasm-interop-temp
skrape-it
slovak
snake
sofl-user-group
southafrica
spacemacs
spain
spanish
speaking
spek
spin
splitties
spotify-mobius
spring
spring-security
squarelibraries
stackoverflow
stacks
stayhungrystayfoolish
stdlib
stlouis
strife-discord-lib
strikt
students
stuttgart
sudan
swagger-gradle-codegen
swarm
sweden
swing
swiss-user-group
switzerland
talking-kotlin
tallinn
tampa
teamcity
tegal
tempe
tensorflow
terminal
test
testing
testtestest
texas
tgbotapi
thailand
tornadofx
touchlab-tools
training
tricity-kotlin-user-group
trójmiasto
truth
tunisia
turkey
turkiye
twitter-feed
uae
udacityindia
uk
ukrainian
uniflow
unkonf
uruguay
utah
uuid
vancouver
vankotlin
vertx
videos
vienna
vietnam
vim
vkug
vuejs
web-mpp
webassembly
webrtc
wimix_sentry
wwdc
zircon
Powered by Linen
language-proposals
  • s

    Slackbot

    07/01/2021, 12:53 AM
    This message was deleted.
    g
    d
    • 3
    • 2
  • t

    Tomasz Krakowiak

    07/01/2021, 6:12 PM
    I think it would be nice if we could restrict that passing parameters to specific function must use named or positional arguments only. It would make it easier to maintain source compatibility in some cases. I guess it could make it difficult for compiler to preserve binary compatibility for named arguments only functions.
    ➕ 2
    g
    m
    i
    • 4
    • 3
  • h

    hfhbd

    07/19/2021, 11:03 AM
    Hey, what do you think about adding some kind of
    Int/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_literals
    d
    i
    +2
    • 5
    • 13
  • l

    louiscad

    07/20/2021, 3:18 PM
    In multiplatform projects, I find it quite inconvenient to have related files split among separate directories where the common parent is multiple levels away. I just got an idea that could resolve this problem: Using the extension to specify the sourceSet the file belongs to. For example, we'd have
    Stuff.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.
    e
    s
    +2
    • 5
    • 14
  • d

    denis.zharkov

    08/11/2021, 3:27 PM
    There are updates of the proposal based on your feedback! The main change is that we moved from confusing 
    T!!
     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.
    👍 12
    👍🏼 1
    y
    • 2
    • 2
  • s

    simon.vergauwen

    08/16/2021, 6:41 PM
    Hey everyone 👋 Has there ever been any discussion to allow for passing regular lambdas where lambdas with receivers are expected? Effectively, ignoring the receiver of the lambda since it’s unused. See snippet below for example. This would be similar to the current functionality that allows for regular lambdas
    () -> A
    where
    suspend () -> A
    is expected.
    e
    • 2
    • 3
  • s

    simon.vergauwen

    08/16/2021, 6:41 PM
    Untitled.cpp
    e
    • 2
    • 3
  • d

    David Gracia

    08/28/2021, 11:40 PM
    Hello everyone! I think I have found a gap in the standard library and I would like to make a design proposal. Although I have read https://github.com/Kotlin/KEEP and checked current in-progress KEEPs, it is not clear to me if I should open an issue or a pull request first (or both). Could someone guide me on how to start my proposal?
    l
    • 2
    • 2
  • p

    pablisco

    09/01/2021, 8:33 AM
    Wouldn’t it be nice to be able to short-circuit functions and constructor calls when one of the params is null 👀 Has something like this been proposed? I’m not sure what to search for in YouTrack 😅 https://twitter.com/pablisc0/status/1432981029812322306?s=20
    f
    m
    e
    • 4
    • 10
  • e

    Emil Kantis

    09/07/2021, 9:30 PM
    Anyone else feel this (
    trySingle
    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
       }
    }
    e
    h
    • 3
    • 9
  • r

    Ruckus

    09/09/2021, 2:42 PM
    Proposal: Add suffixes for smaller primitive numbers Currently, you can specify 3 primitive types will a character suffix: • Double (1d) • Float (1f) • Long (1L & 1uL) It would be nice to be able to do the same for smaller types • Byte (1b & 1ub) • Short (1s & 1us) • Int (1i & 1ui)
    f
    • 2
    • 6
  • e

    Endre Deak

    09/24/2021, 8:50 PM
    Happy to create a formal proposal, and it’s totally possible I’m overlooking something, but I’d like to check if partial interface implementation delegates is something that’s achievable. Here’s a sample:
    // 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
    .
    u
    r
    • 3
    • 13
  • r

    Ruckus

    09/28/2021, 6:43 PM
    Proposal: Add a
    .=
    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)
    m
    e
    +2
    • 5
    • 7
  • j

    Javier

    10/12/2021, 10:24 AM
    Any reason this is not added?
    fun String.remove(value: String): String = replace(value, "")
    ➕ 1
    c
    • 2
    • 1
  • k

    Klitos Kyriacou

    10/13/2021, 8:57 PM
    If I have a function
    fun 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?
    e
    e
    j
    • 4
    • 3
  • n

    Nathan Bedell

    10/15/2021, 1:57 PM
    I'm curious, has anyone ever proposed anything like this before?
    class 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.
    d
    • 2
    • 1
  • l

    LastExceed

    10/30/2021, 8:01 AM
    allow
    lateinit
    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
    }
    e
    a
    • 3
    • 7
  • r

    Rob Elliot

    11/03/2021, 11:16 AM
    Would there be any interest in providing a mechanism to make a foreign type implement an interface?
    s
    d
    +2
    • 5
    • 15
  • e

    eduardog3000

    11/03/2021, 6:51 PM
    I just noticed ECMAScript 2021 added exactly this with their "logical nullish assignment"
    ??=
    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.
    👎 1
    👎🏻 1
    m
    j
    • 3
    • 2
  • s

    Scott Christopher

    11/04/2021, 10:31 PM
    Wondering what others think about whether it should be possible to implement a sealed interface that exists in a different package by delegation. It would still ensure that the implementation remains the same as one that exists within the same package as the sealed interface.
    e
    y
    • 3
    • 5
  • s

    Scott Christopher

    11/16/2021, 11:27 AM
    Has there been any prior consideration into extending smart casting to support type parameters, such that something like the following could be possible? (Or is some variation of this already possible?)
    sealed 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
    }
    r
    • 2
    • 4
  • m

    Miguel Vargas

    11/18/2021, 8:05 PM
    file-private should have its own keyword so we can designate class members as file-private
    package a
    
    class B {
      // only accessible from within this file
      file-private val priv = 123
    }
    
    fun c(b: B) {
      println("I can access ${b.priv}")
    }
    👍 4
    ➕ 12
    👍🏼 1
    j
    l
    +2
    • 5
    • 13
  • j

    joseph_ivie

    11/22/2021, 10:29 PM
    Something like the "with statement" in Koka could drastically reduce the number of nested curly braces in some situations. https://koka-lang.github.io/koka/doc/book.html#sec-with Something like this:
    fun example() {
        wrapped with with(SomeDSL)
        dslCall()
    }
    desugars to:
    fun example() {
        with(SomeDsl) { 
            dslCall()
        }
    }
    i
    • 2
    • 3
  • m

    Michael Böiers

    12/02/2021, 10:00 PM
    Wouldn’t it be great if I could easily create an immutable version of an instance of a data class with mutable properties? I wonder how that could be done. It’s not easy, but it would be really cool if I could define something like a
    MutablePerson
    , and it would then automatically have a method
    toPerson(): Person
    .
    j
    p
    +2
    • 5
    • 7
  • e

    edrd

    12/03/2021, 4:40 PM
    Proposal: adopt Compose conventions for enums, singletons and constants. Why? There's no need to call the developer attention SCREAMING_ON_CODE_THAT_CANNOT_CHANGE. A
    const 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.
    👍 10
    e
    j
    +2
    • 5
    • 5
  • a

    Alejandro Serrano Mena

    12/06/2021, 8:52 PM
    hi! I’ve spent some time thinking about how we can improve
    is
    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 checker
    ➕ 11
    :kotlin-intensifies: 1
    👀 2
    e
    d
    • 3
    • 5
  • m

    Michael de Kaste

    12/07/2021, 8:57 PM
    any chance
    sealed fun interface
    will be added in the future?
    r
    p
    • 3
    • 7
  • j

    jimn

    12/10/2021, 2:24 PM
    Octal notation should be more helpful than just flagging a compilation error; parsing Octal is an ugly hack in kotlin. having a IDE/compiler expression to recognize the prefix and tell you "something is here, and you can't use it" is suboptimal.
    i
    • 2
    • 10
  • h

    henrik

    12/14/2021, 12:25 PM
    Would it make sense for Kotlin to provide constant array literals? E.g.
    const val arrayLiteral = ["books", "default"]
    could then be used in an annotation like
    @CacheConfig(cacheNames = arrayLiteral)
    .
    👍 1
    j
    m
    • 3
    • 4
  • e

    ephemient

    12/18/2021, 9:36 PM
    anybody else miss a function like
    fun <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 Ruby
    l
    e
    m
    • 4
    • 7
Powered by Linen
Title
e

ephemient

12/18/2021, 9:36 PM
anybody else miss a function like
fun <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 Ruby
I've come up with what I think is a reasonable implementation,
fun <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 yet
l

louiscad

12/19/2021, 12:49 AM
I think you miss the return type in the signature in your snippet.
e

ephemient

12/19/2021, 12:50 AM
??
: Unit
return type is implied for
{ }
block defined functions
unless you mean that it should return the range that was replaced… no, because that can only be done by a copy. the caller can just as easily
.subList(indices).toList()
first if that's what they want, but it's commonly used enough to warrant being built in here IMO
e

edrd

12/19/2021, 8:48 PM
Or to make it have the same syntax as Python and Ruby do:
operator fun <T> MutableList<T>.set(indices: IntRange, values: Iterable<T>)
l

louiscad

12/19/2021, 11:38 PM
The set operator is less confusing to me compared to "splice"
m

mcpiroman

12/20/2021, 10:06 AM
Btw. any reason there is no such operator for get i.e. we can't do python-like
val a = list[2..5]
? I guess maybe it's difficult to choose whether it should be an alias for `subList`vs
slice
.
View count: 3