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

    Sasso

    03/04/2020, 9:40 AM
    it seems that the 1.3.70 version is not compatible with kotlinx.serialization.runtime 0.14.0
    :yes: 3
    k
    • 2
    • 2
  • p

    phldavies

    03/04/2020, 11:06 AM
    Is there any way to declare a property using a delegate but with a private setter?
    b
    • 2
    • 6
  • p

    Pawel

    03/04/2020, 11:22 AM
    Hey, I am trying to write sequence chain with list of Strings as input, 2 predicates are given and as output I'd like to recieve Map (or Pair?) of list of strings that fullfil predicates (some strings may return true for both). Do you have any ideas? I got requirement working but wondring if this is possible to achieve with one chain
    p
    • 2
    • 1
  • j

    Julio Zynger

    03/04/2020, 12:17 PM
    I’m looking into the std lib functions for Collections, is there a function to get the first index of match to a predicate in the Iterable return null if not found? In other words, I want to avoid a double pass on the Collection by using
    myCollection.indexOf(myCollection.find { predicate(it) })
    (plus avoid the handling of
    -1
    as a result type.
    s
    s
    d
    • 4
    • 9
  • o

    Ola Gawell

    03/04/2020, 12:35 PM
    Hi! Just a short question about Iterable/Squence. Is there an operator like
    forEach
    but that doesn't end the squence/iterator. I can do it with
    map
    and then return the item in the end, but I guess there is an operator for this already.
    list.map { it -> 
      doSomethingWithIt(it)
      it
    }
    s
    • 2
    • 2
  • e

    Egor Okhterov

    03/04/2020, 1:57 PM
    Did someone test kapt
    1.3.70
    ? Build time has increased dramatically, appeared a lot of warnings (about absent directories) and some tasks don't produce artifacts as they did before. I will be waiting for
    1.3.71
    😃
    f
    g
    • 3
    • 4
  • n

    Nikola Milovic

    03/04/2020, 5:22 PM
    Hey guys, need some input on what to do exactly. I am in a spot where I have been working with Kotlin and Android for 1.5 years now and I've been kinda bored atm and don't know what to do. I've made several decent projects that each had specific technology that was gonna be used and learned through it. I know that most people get employed much sooner than this, but I still have 3 months of high school before I can start thinking about a job. Any recommendations on what to do to improve myself? I was thinking of starting writing some libraries, seems challenging and fun, should encourage clean and concise code. Either that or some game dev using Kotlin, that would surely be fun but I'd still want to make more stuff that can be portfolio pieces. Edit: To add to this, thanks for reading first off, secondly, would writing libraries for things that I need or should I write existing stuff (like networking). I don't really need much and most of the stuff is covered.
    m
    a
    • 3
    • 4
  • l

    Luke

    03/04/2020, 6:06 PM
    Is there a function in the standard library similar to
    groupBy
    but returns a
    List<List<T>>
    instead of a map? I don’t need the keys.
    n
    f
    +2
    • 5
    • 11
  • s

    Sourabh Rawat

    03/05/2020, 1:57 AM
    Are @param @returns in kdocs discouraged? Asking because I don't see javadoc like doc comments in stdlib or anywhere based on Kotlin.
    s
    z
    r
    • 4
    • 4
  • m

    Marc Knaup

    03/05/2020, 2:48 AM
    I guess it’s better in terms of performance and predictability to use
    !== null
    and
    === null
    instead of
    != null
    and
    == null
    due to not using
    equals
    ?
    s
    • 2
    • 17
  • j

    jimn

    03/05/2020, 9:13 AM
    this is ported from java. in the original code future[0] appears to be a hack to reach between scopes. is there more than one way to smooth over the array of one hack?
    private fun scheduleTask(address: MemberAddress, command: Runnable, delay: Int, units: TimeUnit) {
            waiting.computeIfAbsent(address) { a: MemberAddress? ->
                  lateinit  var future:  ScheduledFuture<*> 
    
                executor.schedule(loggingExceptions(Runnable {
                    waiting.remove(address, future )
                    command.run()
                }), delay.toLong(), TimeUnit.MILLISECONDS) .also { future=it }
            }
        }
    d
    • 2
    • 3
  • s

    Slackbot

    03/05/2020, 9:14 AM
    This message was deleted.
    m
    r
    e
    • 4
    • 3
  • r

    Robert Jaros

    03/05/2020, 3:13 PM
    And I was just trying to use trailing commas ... ;-/ https://github.com/JetBrains/kotlin/commit/f8c36eb0a0d41fcc000b95e85f6256b57764d872
    😢 3
    c
    • 2
    • 1
  • d

    dam5s

    03/05/2020, 4:56 PM
    Is anyone familiar with this and/or can point me to some documentation on the subject?
    Smart cast to 'String' is impossible because 'myObject.myProperty' is a public API property declared in different module
    z
    • 2
    • 2
  • s

    Sylvain Patenaude

    03/05/2020, 7:59 PM
    When generating libraries to be consumed by external clients (.jar or .framework), what are the preferred ways to include dependencies or to at least make them available to the said consumers? For now, the clients have to include/import the dependencies on their side, but it's something I would like to avoid, to make sure they always have the good versions of the needed dependencies. Thanks in advance!
    m
    • 2
    • 1
  • d

    darkmoon_uk

    03/06/2020, 5:34 AM
    Can anyone recommend a Kotlin-friendly Client/Server Application framework suitable for Mobile where message delivery is assured (mission-critical business requirement). That is to say, workflow event messages are persistently queued for send in either direction, so that if a device is offline/gets restarted etc. delivery is still attempted when the user logs in again.
    s
    • 2
    • 3
  • g

    gian

    03/06/2020, 8:43 AM
    Am I wrong in expecting a smart cast in both cases? 🤔
    fun main() {
        val foo: Foo? = Foo("")
    
        if (foo?.bar != null && foo.bar.isNotEmpty()) {
            println(foo.bar.length) // smart cast
        }
        if (!foo?.bar.isNullOrEmpty()) {
            println(foo.bar.length) // no smart cast
        }
    }
    
    class Foo(val bar: String?)
    o
    f
    d
    • 4
    • 14
  • c

    Cyberpunk Keanu

    03/06/2020, 10:42 AM
    Can someone with good mathematical logic help me out for this? I'm drawing two concentric circles on the screen. The smaller one has a radius startRadius and the outer larger one's radius is endRadius. So, Now I want to get a randomly generated point, which lies in the region between the two concentric circles. Also, is there a way to get significant distance between the previously generated random point & the newly generated random point? I'll be adding imageviews on these points, so don't want overlapping images because the two randomly picked points are almost next to each other. Thanks.
    t
    p
    • 3
    • 4
  • t

    tim

    03/06/2020, 11:13 AM
    Is there a straightforward way to accesses nested properties on a data classes? For example:
    data class Outer(val inner: Inner)
    data class Inner(val value: Int)
    
    val state = Outer(Inner(1))
    
    val keyOuter = "inner"
    val keyInner = "value"
    state[keyOuter][keyInner] // returns 1
    Ultimately I'd like to do is specify a 'path' so I can get at the nested value:
    dataClass["inner.someValue.value"]
    (similar to how lodash does it for javascript objects).
    🇳🇴 2
    m
    j
    • 3
    • 11
  • x

    XQDD

    03/06/2020, 1:16 PM
    Untitled
    l
    m
    j
    • 4
    • 19
  • k

    kevinherron

    03/06/2020, 7:01 PM
    is regularly restarting the IDE because the CPU usage runs wild for no discernible reason part of your lives too?
    🇳🇴 10
    :yes: 2
    ➖ 1
    t
    a
    • 3
    • 4
  • b

    Bob Glamm

    03/06/2020, 7:23 PM
    IntelliJ's dismal performance on Kotlin code as a code editor is a deal-breaker for me, TBH. I can't count the number of times it gets GC-squeezed or Intellisense doesn't work or it takes 3 seconds for the key I type to appear on the screen
    👍 11
    z
    j
    s
    • 4
    • 3
  • l

    LastExceed

    03/06/2020, 8:54 PM
    language design question:
    interface MyInterface<T> {} //interface declaration
    class MyClass<T> : MyInterface<String> {} //class declaration and interface implementation
    val x = MyClass<String>() //class construction
    fun <T> foo() {} //function declaration
    val y = foo<String>() //function call
    type parameters are always specified after the name, except in the case of function declarations. why this inconsistency? why isnt the syntax for it like this
    fun foo<T>() {}
    to be consistent ?
    👍 1
    i
    • 2
    • 1
  • j

    Jakub Pi

    03/06/2020, 10:18 PM
    Is there a preferred library for partial application and similar functionality that is not available in stdlib?
    fun byTagCategoryAndTag(tagCategory : TagCategory, vararg tags : TagInfo) : (TagCategory, TagInfo) -> Boolean = { cat, tag -> tagCategory == cat && tag in tags}
    fun byMatchingTags(vararg tags : TagInfo) : (TagInfo) -> Boolean =  partial(::byTagCategoryAndTag, TagCategory.ROOT)
    k
    • 2
    • 4
  • q

    qwert_ukg

    03/07/2020, 6:29 AM
    Morning. When i try to add
    kotlinx-html
    to my project, getting an error
    Could not transfer artifact org.jetbrains.kotlinx:kotlinx-html:pom:0.7.1
    kotlin
    1.3.61
    <dependency>
                <groupId>org.jetbrains.kotlinx</groupId>
                <artifactId>kotlinx-html</artifactId>
                <version>0.7.1</version>
            </dependency>
            <repository>
                <id>jcenter</id>
                <name>jcenter</name>
                <url><https://jcenter.bintray.com></url>
            </repository>
    What the reason could be?
    l
    • 2
    • 1
  • s

    steenooo

    03/07/2020, 1:45 PM
    Is it possible to rewrite the following code (in the screenshot) to be more compact The type of
    e.entity
    is "Entity". Many classes derive of this interface. But, I only want to do something with them if they're either Horse or Panda. And if they are, I want to do something general, for both panda and horse. And I want to also do something specific for them pandas and for horses I know It is possible to do the current construction, or copy the code which should be executed for both. But I was wondering if there was a more concise way to do this.
    f
    j
    +2
    • 5
    • 5
  • j

    Joshlemer

    03/07/2020, 4:42 PM
    I wonder how common it is to use the extra package https://github.com/Kotlin/kotlinx.collections.immutable in the Kotlin community?
    p
    h
    • 3
    • 2
  • r

    Robert Jaros

    03/07/2020, 10:43 PM
    What could be missing if one subproject of a gradle project is omitted when
    publishToMavenLocal
    task is executed (it doesn't even assemble jars). I have added
    id("maven-publish")
    plugin. The subproject in kotlin/js and the parent project is mpp.
    t
    • 2
    • 3
  • l

    LastExceed

    03/07/2020, 10:49 PM
    why does
    reified
    have to be declared explicitly ? are there cases where you'd want the type parameter of an
    inline
    function to NOT be reified ?
    ➕ 2
    k
    h
    • 3
    • 4
  • h

    Hullaballoonatic

    03/08/2020, 5:11 PM
    is an operation that loops through a collection once performing two operations more/less/equal performance to an operation that loops through the collection twice, performing the first operation then the second?
    myList.toArray { it + 1 }
    v
    myList.map { it + 1 }.toArray()
    to be precise, I'm wondering if Kotlin performs equally well, not simply that they have the same runtime complexity.
    k
    d
    e
    • 4
    • 9
Powered by Linen
Title
h

Hullaballoonatic

03/08/2020, 5:11 PM
is an operation that loops through a collection once performing two operations more/less/equal performance to an operation that loops through the collection twice, performing the first operation then the second?
myList.toArray { it + 1 }
v
myList.map { it + 1 }.toArray()
to be precise, I'm wondering if Kotlin performs equally well, not simply that they have the same runtime complexity.
k

Kroppeb

03/08/2020, 5:28 PM
Doesn't
map
return a list?
d

Dico

03/08/2020, 5:29 PM
In terms of time complexity (O) notation, yes it is. The prior might be quicker though when you factor in cache misses, but this is pure speculation.
h

Hullaballoonatic

03/08/2020, 5:30 PM
I thought it returned
Iterable<int>
in this case, but I might be wrong (been writing too much c#). Not really the point, but touche.
d

Dico

03/08/2020, 5:30 PM
It is equal* is what I mean by yes.
I didn't look at your examples.
k

Kroppeb

03/08/2020, 5:43 PM
I'd assume that
toArray
doesn't use an intermediate so it's faster. However once the JIT desides to optimise it, it becomes hard to see if there is any difference. If you use graalVM I think it's the same, but the standard JVM is most likely a tad slower for the
map{}.toArray
case
h

Hullaballoonatic

03/08/2020, 6:28 PM
either way, i guess if this distinction here matters for your project, Kotlin isn't the right language to go with either way. probably should be using c
d

Dico

03/08/2020, 7:07 PM
All I see here is a lot of assumptions. Assumptions should not be used for important decisions like that.
e

E.Kisaragi

03/16/2020, 6:53 AM
the second one will make list internally by map?
View count: 1