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
  • a

    Andrew Gazelka

    04/22/2019, 7:41 PM
    kinda unsure when a top-level function / class / object is most appropriate for doing things like ProjectEuler. Ideas? https://github.com/andrewgazelka/ProjectEuler/issues/2
    p
    • 2
    • 13
  • s

    Slackbot

    04/23/2019, 1:47 AM
    This message was deleted.
    n
    • 2
    • 1
  • f

    ferrytan

    04/23/2019, 3:49 AM
    Hi everyone, i've got a question about collection, is there any function or trick in kotlin that could merge only adjacent items in collection? for example, i have an object containing string and an integer. let's say i have this array of object: Raw:
    [
       {"A",1}, 
       {"A",1}, 
       {"A",1}, 
       {"B",1}, 
       {"C",1},
       {"D",1}, 
       {"D",1}, 
       {"A",1},
       {"A",1}, 
       {"D",1}
    ]
    I'm aiming to merge the adjacent items and add the integer value for each adjacent items, the end result should transform as this: Result:
    [
       {"A",3}, 
       {"B",1}, 
       {"C",1}, 
       {"D",2}, 
       {"A",2}, 
       {"D",1}
    ]
    I've searched through basic extensions for Collection, closest i can found is using
    windowed
    with
    step
    1 and
    size
    1, but it seems like i have to loop and map the call multiple times until there are no pairs to get the result i wanted. Is there any other way to get around this? I also tried
    zipWithNext
    but it gets tricky if there are more than 2 adjacent items on the list
    y
    a
    +4
    • 7
    • 17
  • d

    Dias

    04/23/2019, 9:18 AM
    Does anyone use any additional kotlin plugins (intellij/zsh etc)?
    d
    r
    • 3
    • 3
  • a

    Andrew Gazelka

    04/23/2019, 2:30 PM
    no package protected makes me so frustrated... no real purpose of having unit tests in same package as what I am testing... to do unit tests practically would need each thing I am testing to be in a seperate module
    ☝️ 4
    ➕ 1
    💯 4
    m
    d
    +2
    • 5
    • 16
  • r

    ribesg

    04/23/2019, 3:02 PM
    I’ve got an issue and I have no idea where it could come from. I’ve got a top level public extension function defined in the common part of a multiplatform project like this:
    fun HttpRequestBuilder.useAuthentication() { ... }
    HttpRequestBuilder
    is from Ktor client. I’m trying to use it in another project which has the above one as a dependency:
    private suspend fun postUploadFile(successUrl: String): Unit =
            <http://http.post|http.post>(successUrl) {
                useAuthentication()
            }
    http
    is a Ktor
    HttpClient
    . IntelliJ IDEA sees the extension, imported it alone without me doing anything, everything works inside IntelliJ. Then I tried to build.
    > Task :compileDebugKotlinAndroid FAILED
    e: <myFile>.kt: (9, 37): Unresolved reference: useAuthentication
    The reference position is in the imports. What could cause that? I’m posting here because I have no idea where to start. It only seem to happen for this top level extension right now. Maybe it’s a Gradle metadata issue? But then why would IntelliJ see it?
    :google: 1
    :stackoverflow: 1
    h
    s
    +2
    • 5
    • 20
  • t

    tschuchort

    04/23/2019, 5:54 PM
    Is
    Foo<*>
    in Kotlin equivalent to
    Foo<?>
    in Java?
    :yes: 1
    k
    s
    +3
    • 6
    • 18
  • n

    Nezteb

    04/23/2019, 7:31 PM
    Is there a builtin function to map a single argument to many functions that take that same argument? i.e.
    val myArg = 1
    val myFuncs = listOf(::addOne, ::addTwo, ::addThree)
    
    myArg.someCoolMapFunctions(myFuncs)
    There’s a stack overflow answer for Haskell to define this function yourself, but I don’t know what the equivalent Kotlin code would be https://stackoverflow.com/a/47501940/7682196
    s
    r
    • 3
    • 9
  • p

    pindab0ter

    04/23/2019, 8:11 PM
    How do you generate a
    <http://pl.kotl.in|pl.kotl.in>
    URL for the Kotlin Playground?
    b
    • 2
    • 2
  • n

    Nezteb

    04/23/2019, 9:37 PM
    What is the name for each of these ways to reference a function?
    ::funcName
    funcName
    funcName()
    ? The last one I believe is a function invocation, ie
    () -> Unit
    , but the first two confuse me.
    a
    c
    s
    • 4
    • 4
  • n

    Nezteb

    04/24/2019, 1:06 AM
    Is there a good Java/Kotlin lib for handling dates? Something similarly usable as Moment.js
    s
    b
    +2
    • 5
    • 21
  • j

    Julien Cayzac

    04/24/2019, 1:34 AM
    Hello, I don't understand why the compiler complains here about the missing branch in
    when
    . The
    require
    clause implies
    element
    cannot be a
    JsonNull
    :
    fun unbox(element: JsonElement): Any {
        require(element !is JsonNull) { "The token contains null values" }
        return when (element) { // error: JsonNull case missing
            is JsonLiteral -> element.body
            is JsonArray -> element.filter { it != JsonNull }.map { unbox(it) }
            is JsonObject -> element.content.filterValues { it != JsonNull }.mapValues { unbox(it.value) }
        }
    }
    m
    • 2
    • 10
  • a

    am414

    04/24/2019, 3:04 AM
    hello everyone private val CURRENT_DATE_PREF_VALUE = "cdate" to "" "to" refers to what?
    g
    j
    • 3
    • 6
  • i

    itnoles

    04/24/2019, 3:04 AM
    map?
    🇳🇴 2
    a
    • 2
    • 1
  • m

    marcinmoskala

    04/24/2019, 6:50 AM
    Is there a way to reference member extension function?
    class A
    class B {
        fun A.update(i: Int) {}
    }
    g
    p
    • 3
    • 6
  • s

    Shawn A

    04/24/2019, 3:02 PM
    I have a question about type inference in the example below. Given this method:
    fun <R : Any> fromAttr(
            prop: KProperty1<T, R>,
            transformer: (AttributeValue) -> R
        ) {
            transformers.put(constructorParams.getValue(prop.name), transformer)
        }
    If I don't supply the type argument I am able to pass a
    prop
    with a different
    R
    than
    transformer
    . For instance:
    u.fromAttr(Widget::count) { false }
    Where
    Widget::count
    is a
    Long
    . I have to use the form
    u.fromAttr<Long>(Widget::count) { false }
    to get a compiler error. I assume this is happening because of type erasure so Kotlin is inferring
    R
    to be
    Any
    ?
    d
    • 2
    • 13
  • n

    Nezteb

    04/24/2019, 3:44 PM
    What are people’s preferred Java community Slack groups? I’d like to join one alongside this one.
    s
    c
    • 3
    • 2
  • e

    egorand

    04/24/2019, 5:40 PM
    is there a
    fun Map<K, V>.map()
    that returns a
    Map<K, V>
    ?
    d
    • 2
    • 4
  • j

    jcogilvie

    04/24/2019, 6:39 PM
    anybody seen "Insufficient maximum stack size" lately? kt 1.3.30, happens during method inlining using
    Katana
    for DI.
    Caused by: java.lang.IndexOutOfBoundsException: Insufficient maximum stack size.
            at org.jetbrains.org.objectweb.asm.tree.analysis.Frame.push(Frame.java:239)
            at org.jetbrains.org.objectweb.asm.tree.analysis.Frame.execute(Frame.java:281)
            at org.jetbrains.kotlin.codegen.inline.MethodInliner$Companion$analyzeMethodNodeBeforeInline$analyzer$1$newFrame$1.execute(MethodInliner.kt:1031)
            at org.jetbrains.org.objectweb.asm.tree.analysis.Analyzer.analyze(Analyzer.java:187)
    a
    • 2
    • 4
  • a

    arosenb2

    04/24/2019, 11:35 PM
    Has anyone used TestContainers with Kotlin+JUnit? I'm trying to use it for spinning up a redis container that's controlled by the test suite
    • 1
    • 2
  • a

    Andrew Gazelka

    04/24/2019, 11:46 PM
    is there anything like
    Channel#send()
    but that does not suspend? I know I can use
    Channel(UNLIMITED)
    , but I want to have an interface like a channel that I know will never suspend when I send. The reason for this is I have a function which intakes a channel and outputs data so the inner workings of the function can be recorded (for the purpose of displaying internal, intermediate states within the function).
    g
    • 2
    • 2
  • s

    Steve Merrony

    04/25/2019, 6:50 AM
    I'm considering moving a large project from Go to Kotlin. It's too big to rewrite in one go so I need to take a phased approach. What's a good way to call Kotlin code from Go? I need (i) nothing too fancy (i.e. not a framework) and (ii) high performance (there'll be 1000s of calls per second).
    g
    c
    +3
    • 6
    • 22
  • r

    ribesg

    04/25/2019, 7:27 AM
    There is a Kotlin version
    1.3.31
    ? Any info about it?
    g
    • 2
    • 3
  • v

    vach

    04/25/2019, 10:13 AM
    yeah basically its always there you cant get rid of it, but if you have no
    .java
    files it almost doesnt take time... makes sense
    m
    • 2
    • 4
  • v

    vach

    04/25/2019, 10:14 AM
    Different question, when i run maven goals and it does use incremental kotlin compilers, once the maven part is done intellij does this all over again, it compiles the whole thing... is there a way to make intellij reuse what maven did, or basically delegate such compilation tasks to maven? to reuse this the work done
    p
    • 2
    • 1
  • s

    Slackbot

    04/25/2019, 5:07 PM
    This message was deleted.
    r
    • 2
    • 1
  • r

    rootandy

    04/25/2019, 8:19 PM
    Hey, maybe somebody can help me: I try to create a property with a list of elements, where the element have to inherit from a specific class and has to implement a specific interface. I ended up in sth like this:
    private val <T> buffer: List<T> where T : A, T : SomeInterface
    Problem: this is not working since
    T
    is not used in "its receiver type" - can somebody help me with the correct syntax for my purpose?
    s
    k
    • 3
    • 9
  • a

    Antanas A.

    04/26/2019, 11:55 AM
    Hi, does any one knows a good dependency container to use in Kotlin for backend projects? Good means: work without any configuration and extra plumbing code in trivial cases. E.g. val di = Container.scanAllProject(); di.get(SomeService::class) would create and return a singleton of class "SomeService" with autowiring/resolving constructor injected dependencies automatically.
    r
    s
    +7
    • 10
    • 39
  • j

    juliocbcotta

    04/26/2019, 2:45 PM
    Does using
    const val
    instead of
    val
    in a
    companion object
    triggers any compilation/bytecode optimisation ?
    s
    g
    k
    • 4
    • 8
  • s

    SrSouza

    04/26/2019, 3:07 PM
    Why inline classes does not support generic types?
    r
    s
    +2
    • 5
    • 5
Powered by Linen
Title
s

SrSouza

04/26/2019, 3:07 PM
Why inline classes does not support generic types?
r

ribesg

04/26/2019, 3:09 PM
Because it’s not a real class. Think about what an
inline class
is for a minute. Try to find how generics could work with that
s

streetsofboston

04/26/2019, 3:10 PM
I don’t know why, but this can be a ‘workaround’:
inline class Wrap<T>(private val _value : Any?) {
    val value : T get() = _value as T    
}
m

Mike

04/26/2019, 3:15 PM
I suspect that if you do that, you lose any benefit an inline class might provide as the compiler won’t ever be able to inline. Plus the other intent of inline classes is to provide Stronger typing around common types. What is the value of using Wrap versus just defining your variable as whatever T is? I think you should review what inline classes do, and why they exist.
👍 6
s

streetsofboston

04/26/2019, 3:16 PM
^^^ Good point
i

ilya.gorbunov

04/26/2019, 11:04 PM
Currently generic value type in inline classes is not supported because it's unclear how exactly to represent such inlined value. See the options in https://github.com/Kotlin/KEEP/blob/master/proposals/inline-classes.md#generic-inline-class-mapping
View count: 3