https://kotlinlang.org logo
Docs
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
announcements
  • s

    Slackbot

    04/19/2021, 12:20 PM
    This message was deleted.
    :not-kotlin: 5
    b
    j
    b
    • 4
    • 7
  • g

    geepawhill

    04/19/2021, 1:33 PM
    I have
    method(input:Set<X>):Set<X>
    , which wants to transform each element of the (small) set, seemingly a natural fit with
    .map { }
    , but, the transformation can produce invalid individual values, and if that occurs the method's result will be
    emptySet()
    . In other words, under some conditions i want to short-circuit the mapping and just return the empty set. I am wondering if there is some clever stream-ish/sequence-ish way to accomplish this, or should I just go with a for-in and a result accumulator?
    z
    • 2
    • 4
  • e

    Eivind

    04/19/2021, 2:16 PM
    Is there a way to add a companion object to a class from another library. So that i can add extension methods to it. Trying to find a nice way to do SomeDtoClass.generate(10) for a testing solution. Or are there som other nice way?
    🇳🇴 1
    b
    e
    +2
    • 5
    • 7
  • h

    Harry B

    04/19/2021, 8:06 PM
    Hey! Is there a way to make a TCP listener with kotlin native?
    o
    • 2
    • 7
  • v

    Vivek Modi

    04/19/2021, 9:09 PM
    Hey anyone has expert in paging 3 library. I need help. I am working on unlimited data with Viewpager 2 and Paging library. I successfully created the logic to create unlimited pages by the help of paging source. I am swiping single pages by buttons in both direction. But some issue like a weird race scenario where the smooth scroll behavior in ViewPager is attempting to do an animated scroll to an absolute position, but Paging is able to PREPEND items to the front of the list faster than the animation can scroll there. Can anyone know how to solve the problem. I asked in stack overflow but i didn't get it
    e
    • 2
    • 1
  • n

    nkiesel

    04/19/2021, 10:28 PM
    I just noticed a behavior change in Kotlin 1.4 (after finally upgrading a project from 1.3):
    mapOf("a" to 1L, "b" to 2)
    now has a type
    Map<String, Long>
    while it had type
    Map<String, Any>
    in 1.3. This caused a runtime error because the
    2
    was passed to some Java code which then casts it to an
    int
    . It was easy enough to fix by using `mapOf<String, Any>("a" to 1L, "b" to 2)`but it makes me wonder: could I somehow prevent the automatic promotion of the
    2
    to a
    2L
    ?
    s
    r
    t
    • 4
    • 8
  • m

    Michael Böiers

    04/20/2021, 2:50 PM
    Today I looked for something like a conditional let or run, but found nothing. How about this - would something like it make sense in the standard library? https://pl.kotl.in/EI387hmPU
    inline fun <T> T.thatIf(condition: Boolean, block: T.() -> T) = if (!condition) this else block()
    inline fun <T, R> T.thatIf(condition: Boolean, default: R, block: T.() -> R) = if (!condition) default else block()
    
    inline fun <T> T.letIf(condition: Boolean, block: (T) -> T) = if (!condition) this else block(this)
    inline fun <T, R> T.letIf(condition: Boolean, default: R, block: (T) -> R) = if (!condition) default else block(this)
    
    val ALL_TO_LOWER = true
    val APPEND_SIZE = false
    
    fun main() {
        val foo = "Foo"
            .thatIf(ALL_TO_LOWER) { toLowerCase() }
            .thatIf(APPEND_SIZE) { "$this ($length)"}
    
        val bar = "Bar"
            .letIf(ALL_TO_LOWER) { it.toLowerCase() }
            .letIf(APPEND_SIZE) { "$it (${it.length})"}
        
        println("$foo $bar")
    }
    y
    n
    j
    • 4
    • 5
  • u

    user

    04/20/2021, 2:58 PM
    message has been deleted
    j
    r
    +3
    • 5
    • 6
  • a

    Aditya

    04/20/2021, 4:50 PM
    Hi everyone. I wanted to know, how can we integrate network and database interaction capabilities in Kotlin Jetpack compose for Desktop apps ? If anyone have worked on this part, may also share github repositories if any..
    i
    • 2
    • 1
  • p

    poohbar

    04/20/2021, 8:20 PM
    I really need to call a Kotlin method with reified type parameter from Java. Is there no workaround? I am willing to add utilities or even use reflection if needed.
    d
    r
    e
    • 4
    • 7
  • e

    eygraber

    04/21/2021, 12:31 AM
    Another change is a set of new factory functions for creating 
    Duration
     instances from integer values. They are defined directly in the 
    Duration
     type and replace the old extension properties of numeric types such as 
    Int.seconds
    .
    I saw ☝️ in the release notes for 1.5 RC, and I'm curious what the reasoning is for deprecating the extension properties. I found it to be a very nice API. Was it about polluting the namespace?
    ➕ 1
    👀 1
    k
    j
    +5
    • 8
    • 26
  • g

    Grigorii Yurkov

    04/21/2021, 7:38 AM
    Is there a reason I cannot write
    if (list is List<MyClass>)
    ? Compiler forces me to write
    if (list is List<*>)
    . So I have to write
    if (list as? List<MyClass> != null)
    to smartcast my list
    r
    • 2
    • 4
  • m

    Marko Novakovic

    04/21/2021, 8:46 AM
    when implementing custom properties,
    ReadWriteProperty
    for example, it uses
    kotlin.reflect.KProperty
    . do properties use reflection or
    KProperty
    is there to enable reflection?
    e
    • 2
    • 1
  • j

    Jukka Siivonen

    04/21/2021, 11:08 AM
    Should smart cast work in case of
    if (myNullable?.status in listOf(FOO, BAR)) { <myNullable not nullable here> }
    j
    r
    d
    • 4
    • 9
  • e

    edrd

    04/21/2021, 1:05 PM
    In 1.5.0-RC it's still necessary to specify languageVersion/apiVersion properties (at least in Maven) to use sealed interfaces. Is this expected?
    e
    • 2
    • 3
  • d

    dave08

    04/21/2021, 1:20 PM
    I have:
    interface UseCase<in Request : Any, out Response: Any> {
        suspend fun execute(request: Request): Response
    
        suspend operator fun invoke(request: Request): Response = execute(request)
    }
    But when I call an implementation of it in a unit test, it throws:
    usecase.SomeUseCase.invoke(Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
    java.lang.AbstractMethodError: usecase.SomeUseCase.invoke(Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
    what could this be?
    e
    • 2
    • 3
  • r

    Rob Elliot

    04/21/2021, 1:42 PM
    Curious what people think of this pattern:
    when (enumValue) {
      Enum1, Enum2 -> doSomethingImperative()
      else -> Unit
    }
    as an alternative to
    val certainEnumConstants = setOf(Enum1, Enum2) // defined in an object, so allocated once for the life of the runtime - recent edit in light of confusion in thread
    if (enumValue in certainEnumConstants) {
      doSomethingImperative()
    }
    I like the lack of need to define and name a
    val enums: Set<EnumType>
    in the first, but I don’t like the need for an
    else
    branch.
    v
    n
    +4
    • 7
    • 32
  • s

    Slackbot

    04/21/2021, 8:28 PM
    This message was deleted.
    n
    • 2
    • 1
  • s

    Slackbot

    04/21/2021, 8:41 PM
    This message was deleted.
    n
    • 2
    • 1
  • k

    Karlo Lozovina

    04/21/2021, 9:58 PM
    when I dont' use the result of the builtin
    copy()
    function of data classes Intellij highlights the code as a warning (with error of "Unused result of data class copy"). is there a way to get warning activated for my own functions, when I don't use the result value?
    n
    i
    +2
    • 5
    • 6
  • s

    Shailan Patel

    04/22/2021, 12:22 AM
    does anybody know how https://pastebin.com/5JYdjBeE differs from https://pastebin.com/jr3DxT5a ?
    n
    • 2
    • 1
  • s

    Simon Lin

    04/22/2021, 5:53 AM
    Is there a standard fun that return self when non-null or using the default? for example:
    val a: Int? = null
    a.foo { 0 } // 0
    
    val b: Int? = 1
    b.foo { 0 } // 1
    s
    n
    • 3
    • 2
  • s

    Slackbot

    04/22/2021, 7:00 AM
    This message was deleted.
    n
    m
    +3
    • 6
    • 6
  • u

    user

    04/22/2021, 10:08 AM
    message has been deleted
    🙌 4
    🎉 3
    r
    • 1
    • 1
  • n

    Nikolay Puliaev

    04/22/2021, 11:34 AM
    Hi everyone. Is it possible to sum average values of several Int lists in more beautiful way, to reduce code duplication?
    val red = data.red.map { it.toUByte().toInt() }.average()
    val green = data.green.map { it.toUByte().toInt() }.average()
    val blue = data.blue.map { it.toUByte().toInt() }.average()
    val luminance = red + green + blue
    j
    m
    n
    • 4
    • 54
  • c

    Cicero

    04/22/2021, 12:02 PM
    Hey, a friend of mine is doing a community driven game, he is doing it using compose, thought it might interest some people: https://twitter.com/imakeyouagame/status/1385024136666304516?s=20
    a
    • 2
    • 1
  • h

    Hovhannes

    04/22/2021, 1:20 PM
    Hello everybody. I'm fond of Kotlin, but as I see that Kotlin is used for Android and I use it for Android apps. Why Kotlin doesn't become popular? And why programmers don't use Kotlin for web, desktop apps. I've never seen job positions for Kotlin Developers. Why? There are articles about Kotlin that they say that Kotlin will be one of the most demanded programming languages. But I don't see this.
    o
    t
    +4
    • 7
    • 9
  • d

    David Smith

    04/22/2021, 3:48 PM
    I just discovered that
    Iterable<T>.map
    returns a
    List<R>
    not the original data structure (whatever implemented the
    Iterable
    . This seems very strange to me, is it expected? I would expect the
    map
    function to affect only the contents of the data structure, not the data structure itself.
    n
    v
    +4
    • 7
    • 89
  • c

    Christian Dräger

    04/22/2021, 5:44 PM
    Maybe stupid question but why kotlin doesn’t have a unaryTimes operator? I a not sure if this does make sense mathematically but I am facing a situation where it would be really handy to overload the * while writing a DSL like this
    foo { // will invoke some object as this
        0 {
            // create some list based on Foo and get 0 index of list 
        } 
        * {
            // create some list based on Foo and get all entries of list
        }
    }
    https://kotlinlang.org/docs/operator-overloading.html
    👋🏼 1
    n
    n
    y
    • 4
    • 28
  • p

    pascalchidi

    04/22/2021, 10:58 PM
    Thanks
    a
    • 2
    • 1
Powered by Linen
Title
p

pascalchidi

04/22/2021, 10:58 PM
Thanks
a

Alexey Belkov [JB]

04/23/2021, 8:43 AM
Can you please report an issue to https://youtrack.jetbrains.com/issues/KTOR
View count: 1