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
  • b

    Burkhard

    08/23/2019, 2:41 AM
    Kotlin 1.4 will optimize
    trimMargin
    ,
    trimIndent
    at compile time, see https://youtrack.jetbrains.com/issue/KT-17755 I thought this would also allow for const strings using that. I’m guessing this will be the next step.
    j
    • 2
    • 3
  • l

    Leon K

    08/23/2019, 6:04 PM
    new Proposal: Error-able Types (yes, the name sucks, that should obviously be changed) we have
    nullable
    types, which actually are a big reason why Kotlin is loved so much. but as soon as more complex Problems come into play, we have to go to rather ugly exception-style code, or use
    Either
    /
    Try
    types from libraries like arrow-kt ( or create them ourselves) while using
    Try
    and
    either
    types isn't a big problem by itself, it quickly looses a huge amount of Kotlins consiseness, because it makes you write
    kt
    val someTry: Try<List<Int>> = someTryReturner()
    
    val result = someTry
      .map { it.map { it * 2 } }
      .map { it.sum() }
      .map { "result is ${it.toString()}" }
      .getOrElse { exception -> "There was an error: ${exception.message!!}" }
    println(result)
    This would be a lot easier when written with the nullable type:
    kt
    val someNullable: List<Int>? = someNullableReturner()
    
    val result = someNullable
      ?.map { it * 2 }
      ?.sum()
      ?.let{ "result is ${it.toString()}" }
      ?: "There was an error, but i don't know what kind of error D:"
    println(result)
    Here were obviously missing out on the error information. because of this, i propose to support a
    Result<E, V>
    -like type, that behaves like the already existing nullable. my proposed syntax would look like this:
    kt
    val someExceptional: List<Int>?? = someExceptionalReturner()
    
    val result = someExceptional
      ??.map { it * 2 }
      ??.sum()
      ??.let{ "result is ${it.toString()}" }
      ?: { exception -> "There was an error: ${exception.message!!}" }
    println(result)
    this would make code a lot more readable, and could strongly help to encourage developers to actually handle their errors properly. one additional thing that should be included with this would be a
    runExceptional
    function, that takes a lambda-block that could throw an exception and turns it into an exceptional type. another possibility would be to actually have a more terse way of turning a throwing function into an exeptional:
    fun thisThrows(): String {
      throw SomeException()
    }
    val someExceptional: String?? = thisThrows??()
    the questionmarks could directly turn any function that could throw into an exceptional-type. (this syntax is not possible, as it would be ambiguous in situations where you had a
    (() -> T)??
    value that gets executed, but there should be a solution to that problem.
    m
    r
    +5
    • 8
    • 94
  • k

    katz

    08/26/2019, 11:18 AM
    try without catch or smth like
    tryOrElses
    ->
    val t = try{...}
    <- null on fail
    val t = try{...} else X
    val t = try{} ?: X
    r
    t
    +3
    • 6
    • 13
  • e

    elect

    08/26/2019, 12:20 PM
    small wish, I'd like to have the possibility to
    init
    without body, eg:
    init = bar()
    ➕ 1
    ➖ 4
    f
    s
    +3
    • 6
    • 10
  • s

    salomonbrys

    08/28/2019, 8:29 AM
    Here is an artical in witch I am proposing the notion of const class and const capturing lambda, and why I think it matters: https://itnext.io/designing-a-kotlin-memory-safe-mode-c76c06317c3e
    g
    c
    c
    • 4
    • 10
  • a

    Andy Victors

    08/29/2019, 9:44 PM
    Although Kotlin's Elvis operator has cleaner semantics (
    if (c) a else b
    ) than the classic one (
    a ? b : c
    ) it's still a branching (#if-considered-harmful), it's awkward to write and it is hard to use with nesting. Why not to provide a functional programming style operator
    eitherOr(c, a, b)
    , implemented as a function:
    fun <T>eitherOr(condition: Boolean, first: T, second: T) : T {
        return if (condition) first else second
    }
    After all, we already have things like
    min(a,b)
    , `or(a)`etc.
    s
    c
    +5
    • 8
    • 14
  • d

    DALDEI

    09/10/2019, 4:41 AM
    Untitled
    r
    • 2
    • 4
  • j

    jmfayard

    09/17/2019, 5:20 AM
    object-destructuring-by-name_kt.kt
    g
    • 2
    • 30
  • j

    jmfayard

    09/17/2019, 5:21 AM
    ^^ One thing where JavaScript is better than :kotlin: is that it has object destructuring by name. Kotlin has only destructuring by component order … which is ok-ish in some cases but especially not good if all your properties are String. … or at least this is what I thought and then I realized we can do this in Kotlin too! The pattern is to use
    val (my, destructuring, declaration) = with(object) { Tuple(my, destructuring, declaration)
    It’s stil position based obviously since this is what Kotlin support. But in this case it doesn’t matter because the order of arguments is declared in line, not in another class. It’s also much more general, it works with much more than “the properties of data classes”. We can put whatever we like in the lambda and transform it to a tuple. Update: https://youtrack.jetbrains.com/issue/KT-19627
    👍 3
    r
    m
    • 3
    • 2
  • e

    elect

    09/26/2019, 9:09 AM
    swift initializes nullable variables automatically to
    null
    , could kotlin do the same?
    🇳🇴 4
    😱 1
    k
    l
    • 3
    • 17
  • s

    stantronic

    09/27/2019, 4:34 PM
    Hallo, would this be the right channel to ask questions about inline classes?
    r
    • 2
    • 2
  • d

    Derek Peirce

    10/06/2019, 8:45 PM
    Proposal: the ability to use
    by
    on constructor arguments for delegation.
    class Foo(val bar by Lazy<Bar>) { ... }
    would be syntactic sugar for
    class Foo(barProvider: Lazy<Bar>) {
        val bar by barProvider
        ...
    }
    This pattern appears over a thousand times in the codebase I'm working on, and cutting out the declared
    barProvider
    middle-man would make switching between
    Bar
    and
    Lazy<Bar>
    extremely simple.
    👍 2
    d
    e
    • 3
    • 9
  • s

    stantronic

    10/14/2019, 1:02 PM
    Hi, wondering whether some kind of shorthand might be useful for exposing a value of one type as a super-type with a more restrictive interface. E.g.
    val mylist : MutableList<Thing> exposedas List<Thing>
    - keeping the mutable functionality private to the class, but exposing the immutable interface. What do you think?
    d
    • 2
    • 2
  • j

    jdemeulenaere

    10/15/2019, 11:52 AM
    Not sure whether this was already discussed, but it would be nice to be able to overload the comparison operators (<, >=, ==, etc) other than using compareTo (that must return an Int). I would love to have this for a DSL that is used to write some conditions that can be checked only later in the future. I have this
    BooleanExpression
    object than can be returned by some call, e.g.
    myFutureValue.isGreaterThanOrEquals(aStaticValue)
    . It would be nice if instead I could write that using
    myFutureValue >= aStaticValue
    e
    r
    • 3
    • 2
  • z

    zak.taccardi

    10/18/2019, 4:13 PM
    Would it be feasible to declare nested classes in a separate file? For example: I would like to have
    MyViewModel
    in one file, and
    MyViewModel.State
    in another file?
    j
    e
    • 3
    • 7
  • b

    Bob Glamm

    10/23/2019, 4:12 PM
    Suggest adding
    fun Pair<A, B>.flip(): Pair<B, A> = Pair(second, first)
    to standard library
    r
    • 2
    • 1
  • h

    Hullaballoonatic

    10/25/2019, 3:42 AM
    package-wide suppression:
    @package:Suppress("unused")
    useful in spring, for example
    g
    e
    • 3
    • 12
  • j

    jdemeulenaere

    10/25/2019, 12:56 PM
    For DSLs, it would be nice to be able to overload
    ReadWriteProperty#setValue
    so that we could set a variable from different types. Something like this:
    import kotlin.reflect.KProperty
    
    interface Named {
      val name: String
    }
    
    class MyClass {
      var name by NameDelegate("foo")
    }
    
    class NameDelegate(private var name: String) {
      operator fun getValue(thisRef: MyClass, property: KProperty<*>): String {
        return name
      }
    
      operator fun setValue(thisRef: MyClass, property: KProperty<*>, value: String) {
        name = value
      }
    
      operator fun setValue(thisRef: MyClass, property: KProperty<*>, value: Named) {
        name = value.name
      }
    }
    
    fun main() {
      val namedImpl = object : Named {
        override val name: String = "bar"
      }
    
      val myObject = MyClass()
      myObject.name = "bar" // this compiles
      myObject.name = namedImpl // this does not compile
    }
    h
    k
    i
    • 4
    • 6
  • h

    Hullaballoonatic

    10/27/2019, 8:42 PM
    fun <K, V> MutableMap<K, V>.putAll(vararg pairs: Pair<K, V>): Unit
    kinda strange it's not in the stdlib already...?
    d
    k
    • 3
    • 9
  • h

    Hullaballoonatic

    10/29/2019, 7:06 PM
    i should probably be thoroughly shot down for this idea, but: casting maps to data classes or interfaces
    data class Foo(val foo: Int, val bar: Int)
    
    val foo = mapOf("foo" to 1, "bar" to 2) as Foo
    🤢 1
    k
    e
    • 3
    • 4
  • h

    Hullaballoonatic

    10/31/2019, 8:05 PM
    implicit
    this
    argument for when statements:
    fun Any?.isFalsy = when {
        null -> true,
        etc
    }
    ➖ 9
    k
    d
    +2
    • 5
    • 9
  • l

    louiscad

    11/04/2019, 9:25 AM
    Building upon that, I'd prefer
    when (stuff)
    to allow just calling methods, adding the receiver to the branch conditions, or have
    stuff.when
    do that as a new special syntax. (Thinking about how it would translate to actual uses cases, I think I prefer that latter approach)
    b
    r
    h
    • 4
    • 4
  • a

    Alpesh Vas

    11/07/2019, 6:44 PM
    Hey all, I was working on a project of mine and I needed a function which would intersect two collections based on transform functions provided on both or single collection. But couldn't find any in kotlin stdlib, I think it's not there, so I've created a custom extension function to achieve this. So here's the proposal. I would like to contribute this new extension function in collection standard lib. Will add proper proposal for this if you guys think it's worthy of contribution. By the way this would be my contribution in kotlin if it got accepted. Thanks. Found about this channel from https://github.com/Kotlin/KEEP.
    r
    • 2
    • 2
  • n

    nwh

    11/12/2019, 12:21 AM
    It would be nice if we could copy documentation from another method:
    /** 
      * @copy Foo.bar()
      */
    For methods that do almost identical things but take slightly different parameters. For different params, a
    @param
    tag on the method would override whatever is present on the comment being copied from
    👍 7
    m
    • 2
    • 3
  • q

    Quy D X Nguyen

    11/17/2019, 7:20 PM
    How would I go about proposing a KEEP for something in the issue tracker? I'm really interested in seeing setter overriding be possible.
    g
    • 2
    • 2
  • v

    voddan

    11/20/2019, 10:37 AM
    I see a very common pattern of using 2 properties, private and public, when exposing a mutable container as a read-only interface. Example with Android
    LiveData
    (a kind of observable):
    private val _volume = MutableLiveData(0)
    public val volume: LiveData<Int> = _volume
    Example with lists:
    private val _users = mutableListOf(user1)
    public val users: List<User> = _users
    Are there any ideas that are on the table that would simplify those patterns or allow them to be encapsulated with property delegates?
    r
    i
    m
    • 4
    • 8
  • s

    stantronic

    11/20/2019, 10:47 AM
    My syntax suggestion for that -
    private val users = MutableLiveData(0)
      exposeas LiveData<User>
    ➕ 3
    e
    • 2
    • 6
  • v

    victor-mntl

    11/20/2019, 6:02 PM
    Since Kotlin 1.3 the
    fun main(args: Array<String>)
    function is permited to be simplified as
    fun main()
    (when the entry arguments are not used). My suggest is that, when the arguments of the entry
    main
    function ARE used, the IDE/Compiler may accept just
    fun main(args)
    , assuming the type of
    args
    would be
    Array<String>
    .
    ➖ 14
    r
    k
    k
    • 4
    • 6
  • e

    elect

    11/21/2019, 12:13 PM
    if we have set/get operator on not nullable elements (
    !!
    ) we shall also have it after
    .?
    k
    f
    • 3
    • 4
  • l

    louiscad

    11/21/2019, 5:36 PM
    Proposal: per symbol name experimental opt-in. Use case example : I want to use
    kotlinx.coroutines.invoke
    for
    CoroutineDispatcher
    without having to use either of these two inconvenient options: 1. Adding
    @UseExperimental(ExperimentalCoroutinesApi::class)
    at each use-site 2. Opting-in for all
    @ExperimentalCoroutinesApi
    and being bitten later when other experimental APIs change that I didn't see coming. I'd want to be able to opt-in for these in Gradle config (or compiler config) in a way or another, I can search for ideas on how to define it. The fully qualified name (or a pair of imports + symbol names) would be enough, opting-in for all functions overloads, in a KDoc fashion.
    👀 1
    k
    • 2
    • 2
Powered by Linen
Title
l

louiscad

11/21/2019, 5:36 PM
Proposal: per symbol name experimental opt-in. Use case example : I want to use
kotlinx.coroutines.invoke
for
CoroutineDispatcher
without having to use either of these two inconvenient options: 1. Adding
@UseExperimental(ExperimentalCoroutinesApi::class)
at each use-site 2. Opting-in for all
@ExperimentalCoroutinesApi
and being bitten later when other experimental APIs change that I didn't see coming. I'd want to be able to opt-in for these in Gradle config (or compiler config) in a way or another, I can search for ideas on how to define it. The fully qualified name (or a pair of imports + symbol names) would be enough, opting-in for all functions overloads, in a KDoc fashion.
👀 1
k

Ky Leggiero

11/24/2019, 10:20 PM
Isn't there a compiler argument for this already?
l

louiscad

11/24/2019, 11:29 PM
@Ky Leggiero I'm talking about fine grained opt-in, there's no such compiler argument at the moment.
👍 1
View count: 1