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
getting-started
  • m

    Mark

    09/13/2020, 11:30 AM
    class MyClass {
        fun String.myFun() {
            myFun() // how to invoke top-level extension function instead of itself?
        }
    }
    
    fun String.myFun() {
       ... 
    }
    j
    • 2
    • 1
  • k

    ken_kentan

    09/14/2020, 9:18 AM
    How to divide String by regex? e.g.
    "AAA{foo}BBB{bar}CCC"
    to
    ["AAA", "{foo}", "BBB", "{bar}", "CCC"]
    if regex is
    \{.*?}
    t
    e
    s
    • 4
    • 11
  • k

    keishi kubo

    09/14/2020, 4:36 PM
    Very basic question, How to run ktor project without IntellijIDEA ?? I spent more than a moth. And I almost give up using kotlin… Without IDE, Kotlin is tooooooo difficult. No documentation.
    n
    a
    m
    • 4
    • 6
  • k

    keishi kubo

    09/14/2020, 4:48 PM
    I love kotlin, but should I start from learning Java ?? Without IDE, I can’t do anything…
    n
    m
    • 3
    • 13
  • h

    harry.singh

    09/14/2020, 6:18 PM
    Hey all! I'm trying to use a mutable map with integer values like so:
    val myMap = mutableMapOf<Foo, Int>()
    . When I try to update the map with some integer values(for e.g.
    myMap[Foo] = 3
    ), it is giving me the following error:
    Required
    Int.Companion
    but found
    Int
    Why am I getting this error and how can I resolve it?
    n
    m
    • 3
    • 32
  • s

    Steven Wang

    09/14/2020, 10:49 PM
    fun simulate() {
        // get only regular session and it's
        val sessionSelectedSymbols = toSelectedSymbols(scanResults).filter {
            market.calendar.sessions.find { it.sessionId == it.sessionId }!!.regular
        }
        val targets = groupBySymbol(sessionSelectedSymbols).toMap()
        runBlocking {
            withContext(Dispatchers.Default) {
                targets.toList().map { launch { runSymbol(it) } }
            }
        }
        // will the tasks all finished when call to simulate() returns? or I have to call join on each launched tasks?
    }
    n
    • 2
    • 13
  • n

    Not Me

    09/15/2020, 7:44 PM
    Hi everyone. I’m trying to broaden my criminally-backend-only horizons by going into fullstack a bit and I’m having trouble “getting it”.  I made a rudimentary MPP fullstack app with the template IDEA generates (ktor+react), but there’s a lot I want, but don’t know where to even begin searching for answers: 1. How to improve development experience - the template is gradle based, which is great when you want everything packaged into a neat archive or demo everything with a button, but is clumsy as hell for development (any change requires a gradle re-run, which takes forever). I found “something” here: https://github.com/JetBrains/create-react-kotlin-app , but it’s just another black box full of mysteries, so maybe I’d need a tutorial on how and why, then something to help me figure out how to get this into an existing MPP 2. Improving how my app looks - the answer is “styling”, but I’m so inept at this, I feel like I need someone to show me the whole design-to-implementation process of getting a “pretty” UI. I have a bunch of labels and input fields, but don’t know how to even begin putting together a design to make it not-crappy 3. Internal workings are voodoo - having a solid JVM background, despite knowing just maven, getting to understand how gradle builds everything and how the application gets executed on the backend wasn’t a problem. The JS side is a complete mystery, however. There’s a ton of libraries for JS - react I somewhat get, now that I’ve fiddled with it - but there’s a lot of other things as well, webpack being the most noticable to me. I’d elaborate, maybe, but really don’t even know how, yet. does anyone know of a “how the pros do FE dev and why” guide somewhere? Clearly whole books could be (and probably have been) written on these topics, so I don’t expect anyone to give me an in-depth tutorial right here. I would greatly appreciate a few pointers, maybe links to up-to-date tutorials (seriously, I have a feeling there’s a new JS framework+build system+dependency management every 3-4 months). tl;dr: this is lame, I know, but “how do I frontend developer?”
    r
    s
    j
    • 4
    • 16
  • s

    Steven Wang

    09/15/2020, 8:39 PM
    any good library support load/write data to disc available? e.g. pandas has support to write feather format (I use a lot) or hdf5 file (I use a lot too), I search around for few days, seems could not find any. thought gonna have some library support feather format as it is from Apache Arrow ....
    v
    • 2
    • 3
  • d

    Doug

    09/18/2020, 4:32 AM
    In the following code, I’m trying to reuse a lot of the code from
    ClassA
    and only override a specific function in
    ClassB
    , is there anyway to do that, or do I need to ensure all of the methods require are created?
    interface View {
      fun loadFirstPage()
      fun otherFunction()
    }
    open class ClassA: View {
      override fun loadFirstPage() { ... }
      override fun otherFunction() { ... }
    }
    class ClassB: ClassA() {
      override fun loadFirstPage() { ... }
    }
    when I load
    ClassB
    , I’m only seeing the code from
    ClassA
    be executed
    t
    • 2
    • 1
  • e

    Esa

    09/18/2020, 9:16 AM
    Hi - is there any safe way to obtain the name of the enclosing class of a
    KFunction<*>
    ? I've got a weird situation where kfunction.javaClass.enclosingClass.simpleName works in one situation, but not another situation.
    d
    • 2
    • 2
  • j

    John Guerra

    09/18/2020, 9:32 PM
    I believe it would be more appropriate to post this here, but is there any actual problem with utilizing Units? I've heard mixed stuff about them and how you should use open brackets rather than utilizing a Unit For example
    override fun onEnable() {
      plugin.server.onlinePlayers.forEach(::join)
    }
    Rather than
    override fun onEnable() = plugin.server.onlinePlayers.forEach(::join)
    n
    r
    j
    • 4
    • 8
  • v

    vlad.minaev

    09/19/2020, 8:52 AM
    dumb question - are there any collection method which works as opposite to .slice ? (e.g. returns collection with elements removed at specified range)
    e
    n
    • 3
    • 5
  • j

    John Guerra

    09/20/2020, 1:59 AM
    Another dumb question: If a class contains data of an entity (Such as their position, etc.) would it be viable to just make it a data class? There is nothing in the constructor as everything within is practically modifiable fields to update things such as their current position.
    d
    v
    • 3
    • 5
  • j

    John Guerra

    09/20/2020, 4:59 PM
    Would there be a better way of handling this?
    internal abstract val packetTypes: List<KClass<*>>
    Cause there's times where it'd look like this:
    override val packetTypes = listOf(
        PacketPlayInFlying::class,
        PacketPlayInFlying.PacketPlayInPosition::class,
        PacketPlayInFlying.PacketPlayInPositionLook::class,
        PacketPlayInFlying.PacketPlayInLook::class
    )
    Which honestly isn't always very pretty to look at. If I only add
    PacketPlayInFlying::class
    to the list then the other classes won't be retrieved. I have to manually add each one so they can be detected.
    c
    m
    • 3
    • 3
  • s

    Slackbot

    09/20/2020, 9:21 PM
    This message was deleted.
    m
    • 2
    • 1
  • d

    Daniele B

    09/22/2020, 7:26 PM
    How can I write this code without repeating
    changed
    twice ?
    val changed = changeSelectedCounty()
    if (changed) {
        showDetail()
    }
    I am looking for something like this, but it’s not accepted:
    if (val changed = changeSelectedCounty()) {
        showDetail()
    }
    I would to assign the result to the
    changed
    variable, as it gives more clarity
    n
    c
    +3
    • 6
    • 15
  • a

    Alexander Schell

    09/23/2020, 4:57 AM
    It's wednesday my dudes! 😄
    🐸 2
    😀 2
    n
    • 2
    • 3
  • a

    Ashish Lama

    09/23/2020, 1:23 PM
    I’m thinking of building an app which kinda behaves like an ebook where i have chapters as items in a navigation slider bar(and those items also consisting of sub-items as sub-chapters). These navigation items would have intents to activities/fragments(not sure which would be better to implement). The contents would have both text as well as images. What would be the approach to store those data? Should it be stored in a database and then fetched using an adapter or should i just hardcode it directly to the activities/fragments using textviews and image-views. I would also like to push new content as chapters into the app. Is it possible to do so using an API or would i need to push an update to the app every time i want to add new content.??
    a
    v
    m
    • 4
    • 12
  • w

    Wavecycle

    09/23/2020, 2:24 PM
    I'm having some trouble with a warning with my code "Type inference failed. The value of the type parameter K should be mentioned in input types (argument types, receiver type or expected type). Try to specify it explicitly." I've seen a few of the posts asking this question where people were generally using generics, but I'm not using them here. The code runs fine on 1.4 but wasn't running on codewars where they' running 1.3. Help is appreciated thank you
    class Leetspeak : Encoder() {
    private val leetChars = mapOf<String, String>("a" to "4", "e" to "3", "l" to "1",
    "m" to "/^^\\", "o" to "0", "u" to "(_)")
    override fun encode(source: String?): String {
    return if (source.isNullOrEmpty()) ""
    else source.map { it: Char ->  leetChars.get(it) ?: it.toString() }
    .joinToString("")
    }
    }
    d
    • 2
    • 2
  • m

    Matt Hicks

    09/23/2020, 7:35 PM
    is there any way to do a mobile cross-platform app + webassembly? I want to create an application that runs on mobile and the browser with one codebase.
    r
    • 2
    • 5
  • a

    Amir Eldor

    09/23/2020, 8:14 PM
    Hello. I'm trying to do something like this and not sure what I'm doing. I want to have a Factory of, let's say, Ship. A Game has a mutable list (or whatever) of Ships so I can track all the Ships in my game (more in thread) -->
    n
    v
    • 3
    • 39
  • s

    Steven Wang

    09/24/2020, 1:33 PM
    how to convert list of pairs to a map grouped by one component e.g. second?
    `listOf("A" to 1, "B" to 2, "C" to 1)` to `mapOf(1 to listOf("A", "C"), 2 to listOf("B"))`
    👍 1
    a
    j
    • 3
    • 3
  • m

    Mark

    09/25/2020, 4:46 AM
    Is there any way to write this using a function reference (e.g.
    ::emit
    )?
    suspend fun FlowCollector<Something>.emitNotNull(something: Something?) {
        something?.let { emit(it) }
    }
    s
    n
    • 3
    • 14
  • e

    Esa

    09/27/2020, 12:15 PM
    Hi, I am looking for a function that can help me do the following: I have a collection (unsorted) of elements that I need to transform. After each transformation I will use the result to lookup the next element to transform. Are there any standard functions that does something like this, or will I need to create my own Collection<T>.mapUnsorted function?
    n
    i
    +3
    • 6
    • 26
  • g

    Grian

    09/29/2020, 12:46 PM
    hello! i was wondering how i would go about giving a
    kotlin.test.assertEquals
    a list of valid expected outputs, like can i just pass it a list and if the output of whatever im testing is part of that list itll say the test passed?
    v
    y
    c
    • 4
    • 7
  • p

    Pau

    09/29/2020, 7:21 PM
    Good night from Europe, today I crossed with CommonsWare. How much recommendable are those books?
    c
    • 2
    • 2
  • d

    Daniele B

    09/29/2020, 11:30 PM
    What is the best code to create
    List<DataA>
    and
    List<DataB>
    starting from a
    List<Source>
    ?
    data class Source {
    	val label
    	val valueA
    	val valueB
    }
    
    data class DataA {
    	val label
    	val valueA
    }
    
    data class DataB {
    	val label
    	val valueB
    }
    n
    a
    +6
    • 9
    • 58
  • m

    Mike Conley

    10/01/2020, 4:59 PM
    Can anybody explain what's happening here to me, because IDGI:
    i
    t
    • 3
    • 4
  • c

    Colton Idle

    10/02/2020, 2:31 AM
    What's the "best" alternative to writing static utility functions in java? I know kotlin has companion objects, named companion objects, object classes, top level functions and extension functions... but a majority of the time, would you say that your XYZUtil.java turns into a whole bunch of kotlin extension functions?
    r
    n
    t
    • 4
    • 7
  • v

    Vikas Singh

    10/02/2020, 5:48 AM
    How can we make animations in lazycolumn or lazyrow using compose ? Is there anything like itemAnimator used in recycler view
    i
    • 2
    • 1
Powered by Linen
Title
v

Vikas Singh

10/02/2020, 5:48 AM
How can we make animations in lazycolumn or lazyrow using compose ? Is there anything like itemAnimator used in recycler view
i

Ian Lake

10/02/2020, 5:51 AM
This is a better question for #compose
View count: 1