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
announcements
  • h

    halirutan

    07/29/2018, 12:39 AM
    Following problem: I maintain a Wolfram Language plugin for IntelliJ and one of its tasks is to check if a symbol/variable is defined in the core of the language. I have information of about 50000 (yes, 50k) built-in symbols and for each symbol I have things like name, namespace, options, usage message, etc.. A symbol is uniquely defined by its full name consisting of name and namespace e.g. ``Developer`ToPackedArray`` or ``System`Plot`` where `` ` `` is the divider like
    .
    in Java/Kotlin and the last part is the name and the first part is the namespace (it's called context). Namespaces can be nested like in Java too, so there might be symbol thats in ``My`name`space`symbol``. A simple datastructure for this is to have a hashset with entries
    fullSymbolNames -> symbolInformation
    but I have some operations that need to be blazingly fast because they are called very often 1. Does symbol
    Plot
    exist in the namespace ``System` ``? This can easily be done by prepending the namespace to the symbol-name and simply check if the keys contain such an entry 2. In which namespaces does the symbol
    FooBar
    exists? Not really fast as I have to filter the whole list of values or process all keys. 3. What symbols are in the namespace
    PacletManager
    ? Again, I need to filter all values for this. My current implementation in Java makes this possible by handling several different hashsets/lists but I wonder if anyone can think of a better data-structure to make the 3 operations fast. Note that once I loaded all the information about symbols, the data is read-only and I do not mutate any of it.
    k
    • 2
    • 23
  • m

    martmists

    07/29/2018, 3:52 AM
    How do I create in-memory zip files based on directories I have? e.g.
    fun zipFiles(path: String = "/path/to/dir"): File
    o
    • 2
    • 1
  • e

    elect

    07/30/2018, 9:33 AM
    is there a way to have the deprecation annotation based on some parameters?
    c
    • 2
    • 5
  • m

    marstran

    07/30/2018, 12:41 PM
    You need to check
    categories != null
    . The compiler cannot infer that it's not null from the
    .orEmpty().isEmpty()
    call.
    👍 1
    m
    • 2
    • 4
  • o

    orangy

    07/30/2018, 2:37 PM
    https://twitter.com/jetbrains/status/1023934154352865280
    😀 1
    💯 9
    h
    v
    h
    • 4
    • 6
  • k

    krtko

    07/30/2018, 6:23 PM
    Being able to do this just dawned on me. ❤️
    k
    t
    +3
    • 6
    • 14
  • p

    passiondroid

    07/30/2018, 6:50 PM
    I just published “RecylerView List Adapter Template in Kotlin” https://medium.com/@passiondroid/recylerview-list-adapter-template-in-kotlin-6b9814201458
    🚓 6
    k
    • 2
    • 1
  • b

    brabo-hi

    07/31/2018, 1:27 AM
    "Mutable function parameter are not supported in Koltin" : how can we change object (or string) we're receive in another function ?
    a
    t
    +2
    • 5
    • 8
  • a

    Aregev2

    07/31/2018, 8:48 AM
    Can I access the eap / dev builds of Kotlin 1.3-Mn?
    k
    g
    • 3
    • 9
  • w

    WildRhum

    07/31/2018, 11:48 AM
    Hello ! If someone could help me ... I'm lost 😞 I need to sort a list of object by multiple values. It should be first sorted based on an Int and after if a boolean is true. It's working fine when I do one (Int or boolean) with sortedWith and compareBy, but don't know how to do both. Any suggestion ?
    d
    n
    • 3
    • 17
  • a

    arekolek

    07/31/2018, 2:43 PM
    putting those properties in top-level and annotating the file:
    @file:JvmName("TestCompanion")
    
    const val FOO = "FOO"
    
    class TestCompanion {
    }
    produces byte code that decompiles to:
    import org.jetbrains.annotations.NotNull;
    
    public final class TestCompanion {
       @NotNull
       public static final String FOO = "FOO";
    }
    s
    • 2
    • 1
  • h

    Hexa

    07/31/2018, 3:16 PM
    How do I convert a
    Map<String, List<Items>
    into a
    Map<String, List<Product>>
    , example:
    val someMap: Map<String, List<Items>> =  x
    
     val newMap: Map<String, List<Product>>  = someMap.map { it. }  ??? what to do here?
    k
    • 2
    • 3
  • k

    Kiongku

    07/31/2018, 3:38 PM
    val newMap: Map<String, List<Product>> = someMap.mapValues { it.value.map { Product(it.brand, it.type) } }
    👍 1
    e
    h
    • 3
    • 3
  • f

    frellan

    07/31/2018, 8:12 PM
    I have a map containing keys that map to a list of stuff. I want to iterate all keys of that map and use all entries for each key (a list of stuff) to yield an object that I then collect into a big list of objects. How to I do that? Its
    Map<Int, List<Stuff>> -> List<NewStuff>
    where new stuff is yielded from each list of stuff
    a
    • 2
    • 3
  • f

    frellan

    07/31/2018, 8:16 PM
    Essentially
    .flatMap
    but instead of recieving each entry I want to recieve all values belong to a key
    l
    • 2
    • 4
  • p

    pavel

    07/31/2018, 9:01 PM
    you can do something like this:
    data class Author(val books: List<Book>)
    data class Book(val name: String, val author: Author)
    
    fun Author.withBook(book: Book): Author = this.copy(books = this.books + book)
    • 1
    • 1
  • a

    adams2

    07/31/2018, 10:20 PM
    is there something similar to typesafe heterogeneous containers in kotlin
    h
    • 2
    • 1
  • e

    eygraber

    08/01/2018, 6:22 AM
    Is there a defined difference between
    this::class.java
    and
    javaClass
    in regards to generics? If I have this class defined:
    class Test<T>(
        val me: Class<T>
    )
    And I instantiate it like this, it's fine:
    fun <T> T.test() {
      Test(javaClass)
    }
    However, if I instantiate it like this, it won't compile:
    fun <T> T.test() {
      Test(this::class.java)
    }
    And the error is:
    Type inference failed. Expected type mismatch:
    Required: Test<T>
    Found: Test<out T>
    h
    • 2
    • 1
  • c

    christophsturm

    08/01/2018, 8:34 AM
    is https://youtrack.jetbrains.com down?
    k
    e
    • 3
    • 3
  • s

    Slackbot

    08/01/2018, 9:51 AM
    This message was deleted.
    🚓 10
    h
    p
    • 3
    • 5
  • r

    Ruckus

    08/01/2018, 7:13 PM
    Something like this? (I haven't tested it)
    fun <T> MutableList<T>.upsert(source: List<T>, predicate: (existing: T, new: T) -> Boolean) {
        for (item in source) {
            val index = indexOfFirst { predicate(it, item) }
            if (index >= 0) set(index, item) else add(item)
        }
    }
    (Note that it's adding to the list while still using it. You may want to save new items to a separate list and add them all at the end after processing.)
    💯 1
    a
    p
    • 3
    • 6
  • a

    anosov

    08/01/2018, 7:35 PM
    -.txt
    s
    l
    • 3
    • 4
  • s

    supaham

    08/02/2018, 4:05 PM
    I'm writing a plugin in kotlin that uses a framework which also is written in kotlin (and java). That framework can be standalone, which means it must have kotlin present in its jar. There's a warning that says the framework has kotlin in its jar and may cause unwanted behaviour. I'm just now suffering from this warning which is more of an error preventing me from writing kotlin in Intellij. But the code compiles fine via gradle. I've come to realise the kotlin IJ plugin is misfunctioning because the framework has .kotlin_module files in it (from the kotlin shading). How do I get around this? The only solution I have come up with is to produce a jar with all shades except kotlin which would be used for plugin writing, and one with kotlin shaded which would be the runtime jar. is there any better ideas?
    s
    • 2
    • 18
  • e

    elect

    08/02/2018, 5:54 PM
    we need inline enums, please vote guys https://youtrack.jetbrains.com/issue/KT-23823
    k
    m
    +3
    • 6
    • 9
  • a

    amatkivskiy

    08/03/2018, 7:51 AM
    Hi guys, got a question about `PreconditionsKt.checkNotNull()`: Is that ok that after
    checkNotNull()
    compiler still thinks that the
    value
    can be null?
    class TargetClass(private val value: String? = null) {
        fun functionThatUsesValue() {
            checkNotNull(value)
    
            // Still need to add ?. to the value call
            println("split: ${value?.split(" ")}")
        }
    }
    
    fun main(args: Array<String>) {
        val target = TargetClass()
        target.functionThatUsesValue()
    }
    k
    • 2
    • 1
  • r

    rrader

    08/03/2018, 8:31 AM
    Hi, what do you think about implementing Dependency injection by type alias?
    class RedisCache { }
    typealias Cache = RedisCache
    if we need to chenge it
    class MongoCache { }
    typealias Cache = MongoCache
    g
    • 2
    • 1
  • j

    Jan Vomlel

    08/03/2018, 10:21 AM
    Exist somewhere reaction to Kotlin absence in: https://spectrum.ieee.org/static/interactive-the-top-programming-languages-2018 ?
    c
    d
    +3
    • 6
    • 5
  • p

    pakoito

    08/03/2018, 10:48 AM
    is there any difference between
    fun <B> B?.bla() = 1
    and
    fun <B: Any?> B.bla() = 1
    n
    r
    • 3
    • 4
  • d

    diesieben07

    08/03/2018, 11:50 AM
    I want to split a list into parts based on a condition. Example: Split on even numbers:
    val input = listOf(4, 1, 1, 3, 2, 5, 2)
    val output = input.chunkedBy { it % 2 == 0 } // should be: [[4, 1, 1, 3], [2, 5], [2]]
    Is there such a thing in the standard library?
    🇳🇴 1
    n
    s
    +5
    • 8
    • 38
  • o

    orafaaraujo

    08/03/2018, 7:56 PM
    Hi, everyone Is there a way to ignore a property on
    toString()
    when using
    data class
    ? Something like an annotation...
    a
    a
    • 3
    • 6
Powered by Linen
Title
o

orafaaraujo

08/03/2018, 7:56 PM
Hi, everyone Is there a way to ignore a property on
toString()
when using
data class
? Something like an annotation...
or only overriding it?
a

Andreas Sinz

08/03/2018, 7:57 PM
yes, you need to override it
o

orafaaraujo

08/03/2018, 7:58 PM
okay, thx
a

adam-mcneilly

08/03/2018, 8:04 PM
You could define it outside of the constructor and inside the class itself, but that means it will be excluded from equals/hash code as well. Don't know your use case, might not be okay, but wanted you to know.
o

orafaaraujo

08/03/2018, 8:10 PM
yeap, it's a good option as well I personally think it's even painless than override toString
but depends on the scenario etc thanks!
👍 1
View count: 2