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

    Stefan Peterson

    03/05/2019, 6:32 PM
    I have a `List<*> that I want to make a map out of based on the objects
    id
    . These `id`s are unique. I know I can use
    groupBy
    to create a map but that results in
    Map<Long, List<*>>
    when I would much rather have
    Map<Long, *>
    . Is there a nice idiomatic way to do this in :kotlin:?
    c
    n
    g
    • 4
    • 6
  • s

    Stefan Peterson

    03/05/2019, 6:36 PM
    Ah, don't know how I missed that in the docs. Huge thanks! Also for future reference, this didn't seem like a great channel to post this in, but I couldn't find anything else for just generic language questions. Is there some other place I should know about?
    a
    • 2
    • 1
  • m

    marstran

    03/05/2019, 7:48 PM
    I just stumbled upon this post on /r/kotlin: https://www.reddit.com/r/Kotlin/comments/axnr0o/negative_zero_00_is_equal_to_zero_sometimes/ Why does this happen? Is it a bug?
    println(-0.0 == 0.0) // true
    println("${-0.0 == 0.0}") // false
    s
    c
    +2
    • 5
    • 20
  • l

    LeoColman

    03/05/2019, 7:54 PM
    Is it possible to create a function overload with the suspend modifier without changing packages? I would like to create something like
    fun foo(fn: () -> Unit) {}
    suspend fun foo(fn: suspend () -> Unit) {}
    but in the same package
    s
    c
    • 3
    • 11
  • l

    LeoColman

    03/05/2019, 8:42 PM
    How do you guys solve function overloads with different generics? Is there any way of doing this without creating one overload for every possibility?
    fun foo<A>(a: A) {}
    fun foo<A, B>(a: A, b: B){}
    fun foo<A,B,C>(a: A, b: B, c: C) { }
    ...
    until foo<125> types
    t
    n
    +3
    • 6
    • 10
  • k

    kieran

    03/05/2019, 11:19 PM
    Hello. Can someone please help me understand the difference between, and use-cases for, konan and kotlin-multiplatform plugins. I've spent most of a day looking at the docs and tutorials and samples but I'm still confused. I've also seen one suggestion from a contributor to JetBrains repos that konan is deprecated, and multiplatform should be used, but I can't find any official source backing that assertion.
    k
    s
    • 3
    • 8
  • t

    Tloru

    03/06/2019, 1:02 AM
    Hello, everyone!
    👋🏿 1
    👋 4
    h
    • 2
    • 1
  • x

    xenoterracide

    03/06/2019, 5:40 AM
    is there a way to tell a kotlin ByteArray that it needs to be cast to an array of bytes for an overloaded vararg byte?
    d
    • 2
    • 2
  • j

    jw

    03/06/2019, 5:43 AM
    no. the representations in memory are not the same. you need to do something like
    Array(bytes.size) { bytes[it] }
    to box. i don't think there's built-in array boxing functions
    k
    • 2
    • 2
  • i

    Iaroslav Postovalov

    03/06/2019, 10:21 AM
    how to stop rewatching?

    https://www.youtube.com/watch?v=hg8oYJ8Ez8s▾

    :kotlin: 3
    👏🏻 2
    🎉 4
    h
    m
    • 3
    • 2
  • a

    arekolek

    03/06/2019, 12:03 PM
    What is the rule for the accessibility of constructor arguments within the
    init
    block? If there’s more than one constructor, you can’t access any arguments? Or is it something different?
    d
    • 2
    • 4
  • m

    morbidmerve

    03/06/2019, 12:20 PM
    looking for someone who is familiar with https://github.com/orangy/squash
    j
    h
    • 3
    • 3
  • h

    Hexa

    03/06/2019, 1:26 PM
    Is there any hard and fast rule of when to declare functions as inline and when not declare inline
    k
    m
    s
    • 4
    • 4
  • u

    ursus

    03/06/2019, 2:51 PM
    Does anyone use some kind of generic Result (Success / Error) monad for error modeling?
    g
    n
    m
    • 4
    • 99
  • s

    streetsofboston

    03/06/2019, 2:53 PM
    It is good practice to get rid of exceptions and model your errors. Either is a great way of doing so. Using sealed classes for errors: You can ‘nest’ sealed classes, have nested, yet exhaustive hierarchies
    g
    g
    • 3
    • 2
  • u

    ursus

    03/06/2019, 2:56 PM
    otherwise you might just stick with boolean
    s
    a
    • 3
    • 24
  • y

    Yossi Saiada

    03/06/2019, 3:09 PM
    (0.0).equals(-0.0)  // false
    (0.0) == (-0.0)     // true
    Does anyone can explain it?
    p
    g
    +3
    • 6
    • 11
  • l

    LG

    03/06/2019, 4:47 PM
    Hi! Is it possible to map a MutableMap<String, String> into a MutableMap<String, Float> using a method like
    mapValues
    ?
    :yes: 5
    h
    d
    • 3
    • 3
  • a

    amansinghal

    03/06/2019, 5:09 PM
    Is anyone using kotlin with scala ? I am planing to eventually migrate 10 Million LOC from scala to kotlin. I know that the interoperability with scala isn't good. But just wanted to know if any one has experienced some hurdles/extreme pain points in doing so
    👀 2
    😨 1
    l
    k
    s
    • 4
    • 10
  • l

    LeoColman

    03/06/2019, 8:10 PM
    How to make
    hi
    also display
    : String
    (hint, not typed)?
    g
    • 2
    • 1
  • l

    Luke

    03/06/2019, 8:11 PM
    alt + enter -> Show property type hints
    l
    k
    • 3
    • 10
  • b

    bbaldino

    03/06/2019, 8:17 PM
    i’m wondering if there’s a clever way to chunk a list of Ints based on the delta between the first and last elements. i.e. chunks should be created such that (lastElement - firstElement <= X).
    originalList = listOf(1, 2, 3, 4, 5, 10, 11, 14, 15, 19, 22);
    chunks = originalList.chunkMaxDifference(5);
    chunks = ((1, 2, 3, 4, 5), (10, 11, 14, 15), (19, 22))
    i came up with this, but i wonder if there’s a better way:
    fun List<Int>.chunkMaxDifference(maxDifference: Int): List<List<Int>> {
        val chunks = mutableListOf<List<Int>>()
        if (this.isEmpty()) {
            return chunks
        }
        var currentChunk = mutableListOf<Int>(first())
        chunks.add(currentChunk)
        // Ignore the first value which we already put in the current chunk
        subList(1, size).forEach {
            if (it - currentChunk.first() > maxDifference) {
                currentChunk = mutableListOf(it)
                chunks.add(currentChunk)
            } else {
                currentChunk.add(it)
            }
        }
        return chunks
    }
    p
    l
    • 3
    • 6
  • v

    vinay

    03/07/2019, 6:31 AM
    I really miss IntelliJ's extract method object refactoring in Kotlin. Are there plans to support this?
    g
    • 2
    • 2
  • j

    jakub.dyszkiewicz

    03/07/2019, 3:04 PM
    It seems like
    list + element
    copies the whole list and adds an element. Are there any plan to create truly immutable lists so that plus operator uses old list with pointer to new element?
    d
    c
    s
    • 4
    • 4
  • m

    Marc Knaup

    03/07/2019, 4:18 PM
    Is there any Kotlin'ish way to use default values of function and constructor parameters programmatically or is this only possible with reflection and relying on the internals of the synthetic overloads (which also only works on the JVM)?
    class Test(val a: Int = 1, val b: Int = 2, val c: Int = 3)
    
    fun test() {
    	var a: Int? = null
    	var b: Int? = null
    	var c: Int? = null
    	if (someCondition) a = somethingNonNull
    	if (someCondition) b = somethingNonNull
    	if (someCondition) c = somethingNonNull
    
    	Test(
    		a = a ?: howToUseDefaultValue, // ??
    		b = b ?: howToUseDefaultValue, // ??
    		c = c ?: howToUseDefaultValue // ??
    	)
    }
    n
    a
    • 3
    • 13
  • u

    ursus

    03/07/2019, 5:36 PM
    is
    @Throws
    annotation worth anything in practise?
    d
    j
    k
    • 4
    • 4
  • h

    Hexa

    03/07/2019, 7:20 PM
    is it worth calling the asSequence funtion like this
    kinesisEvent.records.asSequence()
    before calling foreach in this example:
    // event: List<KinesisEvent.KinesisEventRecord>
    
     event.records.forEach {
                try {
                    val putRecordsRequest = PutRecordsRequest()
                    putRecordsRequest.streamName = "test-stream" 
                    val putRecordsRequestEntryList = ArrayList<PutRecordsRequestEntry>()
                    for (i in 0..499) {
                        val putRecordsRequestEntry = PutRecordsRequestEntry()
                        putRecordsRequestEntry.data = it.kinesis.data
                        putRecordsRequestEntry.partitionKey = it.kinesis.partitionKey
                        putRecordsRequestEntryList.add(putRecordsRequestEntry)
                    }
                    putRecordsRequest.setRecords(putRecordsRequestEntryList)
                    val putRecordsResult = kinesisClient.putRecords(putRecordsRequest)
    
                } catch (e: InterruptedException) {
                    //log error here
                }
    s
    a
    m
    • 4
    • 3
  • r

    Rafa

    03/07/2019, 8:29 PM
    maybe a question for someone from jetbrains, unless somebody else knows the answer. But why is it that we only have 5
    component
    extension properties on a collection, but with a data class we generate
    componentN
    up until (what i'm assuming, couldn't find documentation on it) we reach the limit of functions that can be created in a class on the JVM?
    m
    • 2
    • 1
  • p

    pakoito

    03/08/2019, 12:19 AM
    Shame. On the upside, it’s all perf wins optimizing code from there 😄
    k
    r
    +2
    • 5
    • 22
  • a

    Andrew Gazelka

    03/08/2019, 12:27 AM
    for Project Euler / LeetCode projects iyo how does it make the most sense to setup the project? - each problem extends
    Problem<I,O>
    ...
    I
    is input,
    O
    is output and implements
    fun solve(input: I): O
    - each problem extends
    Problem<O>
    where input is provided in constructor - each problem is a top-level function - each problem is a HOF
    • 1
    • 3
Powered by Linen
Title
a

Andrew Gazelka

03/08/2019, 12:27 AM
for Project Euler / LeetCode projects iyo how does it make the most sense to setup the project? - each problem extends
Problem<I,O>
...
I
is input,
O
is output and implements
fun solve(input: I): O
- each problem extends
Problem<O>
where input is provided in constructor - each problem is a top-level function - each problem is a HOF
I'd think functions potentially since if a state does not need to be preserved it should be a function???
I guess functions kinda fail in the case where I want two implementations of the same problem, though
perhaps a HOF is a better solution
View count: 2