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
stdlib
  • c

    Chris C

    05/19/2022, 7:44 PM
    Hi, Apologies in advance if this is the wrong place to ask this. I’m not sure if i’ve misunderstood how readln() should work, but given this code
    fun main() {
        val first = readln()
        val second = readln()
        println("[$first] [$second]")
    }
    and this input
    1
    2
    I’m getting this output
    [1] []
    I would expect
    [1] [2]
    Or?
    n
    i
    • 3
    • 5
  • i

    Igor Kolomiets

    05/21/2022, 4:24 PM
    I was surprised Kotlin stdlib doesn’t have standard function for list comprehension to get head and tail of the list:
    fun <T> List<T>.headAndTail() = Pair(first(), drop(1))
    Does Kotlin offer more idiomatic approach to do this?
    c
    r
    e
    • 4
    • 10
  • a

    Ayfri

    05/21/2022, 6:05 PM
    Any reason why
    capitalize()
    was removed ? It was so util and the new way to do it is great but looks so raw compared to the methods the String class has, also a method
    titlecase()
    would be great :)
    c
    • 2
    • 1
  • m

    Mikhail

    05/21/2022, 11:59 PM
    what are default options?
    Regex
    constructors ain't even documented..
    c
    n
    • 3
    • 9
  • g

    Gianfranco

    05/27/2022, 4:37 PM
    Is there an idiomatic way to go from
    Map<Key,
    Set<Value>>
    to
    Map<Value,
    Key>
    ?
    a
    k
    e
    • 4
    • 5
  • a

    Ali Khaleqi Yekta

    05/28/2022, 6:25 PM
    https://www.reddit.com/r/Kotlin/comments/uzsjcy/seemingly_inconsistent_behavior_of_data_class/
    r
    e
    • 3
    • 4
  • m

    Mark

    05/29/2022, 2:06 AM
    Is there something in the standard library to perform a
    zip
    but with the catch that the second
    Iterable
    contains a count property to indicate the number of items to consume from the first
    Iterable
    ? Perhaps a running fold can do this, but I can’t quite get my head around it! At the moment, I can get the desired results by separately maintaining an
    Iterator
    on the first
    Iterable
    , but this doesn’t feel very clean to me.
    val list1 = listOf('a', 'b', 'c', 'd', 'e', 'f')
    val list2 = listOf(Type2(count = 2), Type2(count = 1), Type2(count = 3))
    
    val expected = listOf(
        Pair(listOf('a', 'b'), Type2(count = 2)),
        Pair(listOf('c'), Type2(count = 1)),
        Pair(listOf('d', 'e', 'f'), Type2(count = 3)),
    )
    
    class Type2(val count: Int) {
    	...
    }
    d
    • 2
    • 3
  • n

    Nick

    05/29/2022, 7:20 PM
    I’d like to create a scheduler app that contains a list of events. Each event has a
    startDate
    and an
    endDate
    . I’d like to determine which events overlap so I can place events in a different column. Is there a way to apply some sort of
    groupBy
    function to accomplish a way for me to group them?
    e
    a
    a
    • 4
    • 15
  • m

    Mikhail

    05/31/2022, 9:58 PM
    Why doesn't
    Regex
    override
    equals
    ?
    e
    i
    t
    • 4
    • 7
  • a

    asad.awadia

    06/01/2022, 12:49 AM
    Is drop/skip the same as a seek (like in a file) in a sequence? Any way to support seeking to a particularl location instead of doing a noop loop
    i
    z
    • 3
    • 5
  • o

    Orhan Tozan

    06/17/2022, 1:00 PM
    What is the easiest way to get a diff of two `List<Int>`'s?
    minus()
    won't do it, since
    list2 - list1
    only shows what
    list2
    has what
    list1
    hasn't.
    k
    e
    n
    • 4
    • 9
  • n

    nkiesel

    06/17/2022, 7:33 PM
    Given that
    Entry
    has a
    toPair()
    method, why does
    Pair
    does not have a
    toEntry()
    method?
    p
    d
    e
    • 4
    • 15
  • a

    asad.awadia

    06/21/2022, 7:21 PM
    Is there a way to convert basic sql to kotlin sequences/collections operations?
    j
    p
    • 3
    • 7
  • m

    mbonnin

    06/22/2022, 3:24 PM
    I'm confused by the
    SuspiciousCollectionReassignment
    inspection. The description says:
    fun test() {
          var list = listOf(0)
          list += 42 // new list is created, variable 'list' still contains only '0'
      }
    But doing the same thing in playground yields
    [0, 42]
    . What am I missing?
    p
    n
    +2
    • 5
    • 18
  • d

    David Bieregger

    06/22/2022, 3:57 PM
    Just stumpled accross this and though this should be a feature: 1. Optional catch variable
    try {
    throw Error("Oh no!")
    } catch {
    console.log("Something bad happened, but don't know what")
    }
    2. Inline try catch without braces
    var result = try throw Error("Oh no!") catch console.log("Something bad happened")
    The question has been transfered to #compiler (https://kotlinlang.slack.com/archives/C7L3JB43G/p1655913770902479)
    z
    d
    +3
    • 6
    • 8
  • m

    Mikhail

    06/26/2022, 8:59 PM
    how the 🦆 ?
    e
    m
    • 3
    • 3
  • j

    Javier

    06/26/2022, 10:59 PM
    Is it possible to have nested lambdas which uses different
    DslMarker
    markers and picking the nested one? If I have two function with the same name, the outermost is used
    kotlin {
        android() // from kotlin
        multiplatform {
            common()
            android() // from kotlin, should be from multiplatform
            jvm()
        }
    }
  • a

    Andy McGhie

    07/04/2022, 11:31 PM
    As per the suggestion cross-posting into #stdlib
    e
    • 2
    • 6
  • k

    Klitos Kyriacou

    07/05/2022, 4:32 PM
    Wouldn't it be nice if package kotlin.io.path was included in the list of default imports? It includes many functions that are preferable to those with the same names in the kotlin.io package. One consequence of it not being included is that, for example, if you start writing "createT", IntelliJ IDEA offers to complete it to "createTempFile" from kotlin.io which is deprecated in favour of kotlin.io.path.createTempFile due to security concerns. But you won't even see the option to choose the latter in the list of suggested completions.
    👍 2
    👎 2
    s
    n
    j
    • 4
    • 3
  • k

    Klitos Kyriacou

    07/06/2022, 9:19 AM
    Would it make sense if
    log(x, base)
    took a default value of
    E
    for
    base
    so as to make
    log(x)
    work just as it does in Java, C, and most other languages, instead of requiring the base to be explicitly passed? It would also form a counterpart of
    exp(x)
    which already implicitly uses a base of
    E
    .
    🤔 1
    i
    • 2
    • 3
  • o

    Orhan Tozan

    07/06/2022, 11:12 AM
    This feels a bit random, but anyone else feel like
    .filter { }
    could have gotten a better name? Everytime I see
    .filter { }
    , my brain has to stand still and figure out if it actually means "filter out" or not. I think
    .where { }
    would have been a more easier name to scan and understand what it does
    ➕ 1
    j
    e
    +3
    • 6
    • 12
  • e

    Eric Ou

    07/08/2022, 1:40 PM
    Explicit/Short hand methods for lazy delegations(In addition to
    lazy()
    , as in
    lazyNone()
    ,
    lazyPublication()
    , and
    lazySyncronized()
    , instead of
    lazy(LazyThreadSafetyMode)
    m
    m
    • 3
    • 6
  • h

    holgerbrandl

    07/14/2022, 11:33 AM
    When using the duration api why is it d.toDouble(DurationUnit.HOURS) instead of the now deprecated (but seemingly more concise) d.inHours?
    👀 1
  • h

    holgerbrandl

    07/14/2022, 11:38 AM
    Is it planned to add common collection aggregators for kotlin.time.Duration such as sumOf? Or listOf(1.hours, 2.minutes).sum()?
  • i

    Igor Kolomiets

    07/14/2022, 9:56 PM
    Is it a bug or a feature?
    fun main() {
        var numbers = emptySequence<Int>()
    
        numbers = sequence {
            yieldAll(numbers)
            yield(1)
        }
    
        println(numbers.iterator().next()) // throws StackOverflowError
    }
    I do realize that such an approach to build up a sequence may seem unnatural, but for my case (I have to implement Kotlin Serialization’s Encoder interface which methods adds/yields next value for the sequence) I haven’t figured out an alternative.
    e
    c
    n
    • 4
    • 6
  • j

    Jonathan Ellis

    07/22/2022, 2:50 PM
    is there a ticket for adding a BiMap to stdlib that I can vote for?
    z
    • 2
    • 1
  • m

    Mikhail

    07/26/2022, 5:56 PM
    there should be
    LazyList<T>
    that consumes
    Lazy<T>
    and produces
    T
  • m

    Mikhail

    07/26/2022, 7:54 PM
    Why doesn't
    Lazy
    implement
    equals
    and
    hashcode
    ?
    d
    e
    j
    • 4
    • 12
  • e

    elect

    08/01/2022, 7:57 AM
    I'd like to check if a range is within another range, ie
    i-2..i+2 in wd.indices
    e
    r
    +2
    • 5
    • 7
  • e

    elect

    08/01/2022, 8:11 AM
    also
    averageBy{ .. }
    on iterables, as shortcut instead of
    map{ }.average()
    r
    e
    • 3
    • 7
Powered by Linen
Title
e

elect

08/01/2022, 8:11 AM
also
averageBy{ .. }
on iterables, as shortcut instead of
map{ }.average()
r

Roukanken

08/01/2022, 8:12 AM
You can simply create an extension function that would do that
Same for the range thingie, actually
e

elect

08/01/2022, 8:13 AM
almost everything can be solved manually, but adding to the std-lib would make it useful for everyone
r

Roukanken

08/01/2022, 8:15 AM
right, my bad, didn't realize we were in #stdlib
e

elect

08/01/2022, 8:15 AM
np
e

ephemient

08/01/2022, 1:21 PM
it's not clear what the return type should be
e

elect

08/01/2022, 1:22 PM
1- we can infer 2- we have a lambda resolution by return type annotation available We can apply the same logic as
count{ }
View count: 6