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

    Michael Bryant

    03/06/2019, 4:27 AM
    hi! i’m super new to kotlin/intellij/gradle. trying to make a k/n project that compiles to macOS and runs macOS tests. the problem I’m having is that
    macosTest > kotlin > sample > SampleTestsMacos.kt
    isn’t finding the
    kotlin.test
    modules. i tried to add the dependencies to the
    macosTest
    sourceSets section, but i’m still just missing something.
    k
    • 2
    • 2
  • b

    bjonnh

    03/06/2019, 5:45 PM
    (or should I just go with Java's ones)
    s
    • 2
    • 19
  • u

    ursus

    03/06/2019, 11:12 PM
    the return@asUncancelableObservable hurts my eyes
    b
    k
    • 3
    • 4
  • k

    Kenneth

    03/07/2019, 10:33 AM
    Hi! I have a list of objects, lets say a list of Person. I want to remove all duplicates from that list based on the combination of person.name and person.age. What is the "kotlin" way to do so?
    d
    d
    • 3
    • 9
  • b

    bjonnh

    03/07/2019, 7:40 PM
    would it be overflowing?
    s
    d
    • 3
    • 4
  • k

    Kenneth

    03/08/2019, 10:43 AM
    Is there an elegant way to split a list of Person for every 10 persons and return a list of object Group(persons(10 or less/rest))?
    d
    w
    m
    • 4
    • 25
  • r

    Richard Cumberland

    03/08/2019, 12:09 PM
    i'm trying to parse an environment variable with a sensible default, and since this is a learning experiment as much as anything else, i'd like to use pattern matching. is this is a sensible approach, or should i stick to assigning the value of a
    try/catch
    ?
    val port: Int = when (val p = System.getenv().getOrDefault("PORT","8080").toInt()) {
          is Int -> p
          else -> 8080
        }
    d
    s
    • 3
    • 14
  • u

    ursus

    03/08/2019, 4:06 PM
    Is it possible for a class to extend 2 lambdas somehow, given they are interfaces?
    class ApiReactionMapper() : (ApiReaction?) -> Reaction?, _(Reaction?) -> ApiReaction?_ {
    p
    t
    • 3
    • 3
  • f

    febs

    03/08/2019, 5:24 PM
    Is it possible to use visibility modifier to have a class which can be returned by a factory but that cannot be created otherwise? Thanks
    s
    • 2
    • 7
  • b

    bjonnh

    03/08/2019, 8:01 PM
    Is that the best way to build a map for a type that only handles length and item(x) :
    /**
     * Applies the given [transform] to each of the Nodes from the NodeList
     *
     */
    inline fun <R> NodeList.map(transform: (Node) -> R): List<R> {
        val array = ArrayList<R>(this.length)
        for (n in 0 until this.length)
            array[n] = transform(this.item(n))
        return array
    }
    p
    • 2
    • 2
  • o

    Olav Hermansen

    03/09/2019, 11:40 PM
    I am taking a Kotlin class at Coursera and in the interactive code challenges I see eq in
    list1.allNonZero() eq true
    , but when I copy code into IntelliJ I get unresolved reference. Is eq part of Kotlinlang or hidden extension in the course code?
    k
    • 2
    • 4
  • b

    bjonnh

    03/10/2019, 4:22 PM
    regarding Sequences (which I totally overlooked, thanks @sitepodmatt): https://typealias.com/guides/kotlin-sequences-illustrated-guide/
    c
    k
    • 3
    • 3
  • k

    Kenneth

    03/11/2019, 12:14 PM
    Shouldn't
    val nodeId: UUID = UUID.randomUUID()
    inside a data class generate a new uuid each time I make a new instance of the class?
    d
    s
    +2
    • 5
    • 8
  • u

    ursus

    03/12/2019, 1:23 AM
    override fun decode(databaseValue: Long) = when (databaseValue) {
            1L -> DbMessageType.APPOINTMENT
            2L -> DbMessageType.FILE
            3L -> DbMessageType.LINK
            4L -> DbMessageType.WEB_MEETING
            5L -> DbMessageType.PIN
            else -> DbMessageType.TEXT
        }
    
        override fun encode(value: DbMessageType) = when (value) {
            DbMessageType.APPOINTMENT -> 1L
            DbMessageType.FILE -> 2L
            DbMessageType.LINK -> 3L
            DbMessageType.WEB_MEETING -> 4L
            DbMessageType.PIN -> 5L
            DbMessageType.TEXT -> 0L
        }
    to get unified - safer, without allocating Pair instance (or any other)?
    s
    d
    • 3
    • 7
  • k

    karelpeeters

    03/12/2019, 8:43 AM
    someFun<SomeImplementation>()
    and remove the
    clazz
    pqrameter.
    😀 1
    d
    e
    • 3
    • 5
  • v

    voddan

    03/12/2019, 1:28 PM
    Why
    object A {
        sealed class B
        
        class C : B()
        class D : B()
    }
    gives
    cane be inherited only by nested classes
    , but
    sealed class B
        
    class C : B()
    class D : B()
    works fine?
    w
    a
    i
    • 4
    • 17
  • a

    azeDevs

    03/13/2019, 10:20 PM
    I have a class that sorts a generic set of objects by name, and had been using a Function Interface to pass in a Function for getting the generic object's name for sorting. I've been struggling to find the Kotlin equivalent to accomplish the same functionality.
    b
    b
    d
    • 4
    • 19
  • e

    Ernesto Gimeno

    03/14/2019, 1:26 PM
    Ray Wenderlich Android Apprentice book looks promising but it is insanely expensive even in PDF and I didn't find relevant opinions about it
    e
    s
    • 3
    • 5
  • o

    oday

    03/14/2019, 1:50 PM
    Kotlin in Action
    m
    • 2
    • 1
  • d

    Dennis Schröder

    03/14/2019, 2:13 PM
    User.find {
                Users[fieldName] eq fieldName
            }.firstOrNull()
    I am using Kotlin Expose DAO Model! And Iam trying to buld a generic query to query for the fieldName by pasing it in. How can I do this? I mean, how can I access the field from
    Users
    by a variable?
    k
    • 2
    • 7
  • p

    poohbar

    03/14/2019, 6:57 PM
    feelsbadman.jpg
    d
    • 2
    • 1
  • v

    Vlad

    03/14/2019, 7:25 PM
    Is there any way to do kotlin koans in IDEA, but from different PCs? I pushed my code to github, but for whatever reason, can't import it through "Learn" menu...
    e
    • 2
    • 1
  • v

    Vlad

    03/14/2019, 7:26 PM
    I've got the most recent IDEA (installed today)
    e
    • 2
    • 2
  • c

    CanOfBees

    03/14/2019, 9:19 PM
    Hi all - not sure if this is the most appropriate place for this kind of question, but here goes: I'm trying to get my toes damp with Kotlin by working on a command line utility to do image conversions (specifically TIFF to JP2K (JPEG2000)). My general question is: how the heck do you pick libraries for this? I don't have any indepth familiarity with the Java library ecosystem (I know that it's vast). How do you all make determinations about these sorts of things? Many thanks in advance - I appreciate your time and trouble!
    s
    • 2
    • 2
  • l

    leosan

    03/15/2019, 10:58 AM
    is there a better way to achieve this? I have a list and I want to compose it into 4 different lists
    with(screens) {
                filter { it.showProgress }.mapTo(hasProgressScreens) { it.viewId }
                filter { it.showSkip }.mapTo(hasSkipScreens) { it.viewId }
                filter { it.showToolbar }.mapTo(hasToolbar) { it.viewId }
                filter { it.showBack }.mapTo(hasBackButton) { it.viewId }
            }
    d
    a
    +2
    • 5
    • 14
  • m

    Matt

    03/15/2019, 2:42 PM
    Hello all I'm adding entries to a map and I'd like to merge the values where the key already exists. For example, if I have:
    val myMap = mutableMapOf<String, List<String>>()
    and try to add:
    myMap["a"] = listOf("1")
            myMap["a"] = listOf("2")
    I'd like to have:
    "a"=["1","2"]
    How can I achieve this? Can I achieve it using an immutable map?
    d
    m
    • 3
    • 15
  • c

    cspotcode

    03/15/2019, 7:27 PM
    Can I have overridden
    val
    fields in an enum? Something like this? Or do I have to refactor them into getters?
    enum class Foo {
        abstract val bar: String
        FIRST { override val bar = "FIRST BAR" }
        SECOND { override val bar = "SECOND BAR" }
    }
    s
    d
    r
    • 4
    • 6
  • m

    matt tighe

    03/15/2019, 9:19 PM
    i’m trying to use this library to extract a tar file https://github.com/kamranzafar/jtar but i’m having trouble converting the example to kotlin since assignment doesn’t work in while conditions. how can i accomplish the same thing in kotlin, or does anyone have a suggestion for a kotlin-first library for this task?
    a
    t
    n
    • 4
    • 3
  • r

    Richard Green

    03/18/2019, 10:33 AM
    Can anyone tell me why I can’t write something like this
    fun fatal(m: String): Nothing {
        with(TermColors()) {
            println(red(m))
            System.exit(1)
        }
    }
    s
    d
    • 3
    • 3
  • n

    Nicolas Pittion-Rossillon

    03/18/2019, 10:51 AM
    Hello guys! I’m facing troubles with a
    Maven
    multi-modules project in Kotlin; i can’t seem to import a Kotlin module as dependency the way I would have done it in Java. Getting an
    Unresolved moduleName
    though IntelliJ is happy. Could someone point me towards the right channel or person to investigate? Please 😁
    n
    • 2
    • 4
Powered by Linen
Title
n

Nicolas Pittion-Rossillon

03/18/2019, 10:51 AM
Hello guys! I’m facing troubles with a
Maven
multi-modules project in Kotlin; i can’t seem to import a Kotlin module as dependency the way I would have done it in Java. Getting an
Unresolved moduleName
though IntelliJ is happy. Could someone point me towards the right channel or person to investigate? Please 😁
n

nfrankel

03/19/2019, 7:12 AM
can you share your project’s pom? because that seems strange
n

Nicolas Pittion-Rossillon

03/19/2019, 9:18 AM
Sure, i'll set up a small version and share it on github. Thanks for your interest!
Alright, my issue was actually caused by an unfortunate configuration of spring's dependencies by my sorry self. My project imports spring without inheriting from it, and the required spring dependencies were not properly set up. The resulting error message led me the wrong way - hence, my apologies for the disturbance. Fixing a small example project to reproduce the issue helped me understand - hence, my thanks for indirectly setting me on the right path.
👍 1
:rubber_duck: 1
n

nfrankel

03/19/2019, 6:08 PM
happy to have been of service 🙂
👍 1
View count: 2