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

    rrader

    12/24/2018, 1:52 PM
    BTW, is there an issue tracker for Kotlin stdlib?
    c
    l
    • 3
    • 3
  • d

    Dmitry Kandalov

    01/04/2019, 5:46 PM
    Is there any way to get the seed of
    kotlin.random.Random
    ? I want to use
    Random
    in a test with random seed which I could print in case the test fails.
    o
    m
    • 3
    • 5
  • k

    karelpeeters

    01/14/2019, 4:47 PM
    The same can be said for
    %
    .
    ➕ 3
    c
    d
    +2
    • 5
    • 5
  • s

    Shawn

    01/14/2019, 4:49 PM
    Or
    ^
    or
    |
    c
    k
    +2
    • 5
    • 13
  • a

    alexfacciorusso

    01/15/2019, 4:27 PM
    Has the introduction of something like:
    fun <T> Boolean.map(valueTrue: T, valueFalse: T): T = if(this) valueTrue else valueFalse
    in the stdlib been already asked/taken into consideration?
    s
    s
    j
    • 4
    • 8
  • l

    louiscad

    01/17/2019, 9:12 AM
    I think it could be great to add
    countIndexed
    and
    sumByIndexed
    to the stdlib. In an effort to remove a
    var
    and a
    forEachIndexed
    , I came across this need. However, I'd not want to bloat the stdlib. Please, add your ➕ if already needed one of these functions.
    p
    m
    • 3
    • 7
  • m

    Marc Knaup

    01/28/2019, 12:37 PM
    Idea: A
    joinToString
    parameter which allows something like that:
    listOf(1,2,3,4).joinToString(separator = ", ", lastSeparator = " or ")
    ->
    "1, 2, 3 or 4"
    👍 1
    s
    • 2
    • 2
  • a

    alexfacciorusso

    01/28/2019, 2:18 PM
    hey guys, silly question: what's the best way of formatting a Float/Double to String with a given number of decimals in Kotlin common? Is there any plan of integrating a
    .format
    or
    .toString(decimals)
    in the common stdlib?
    j
    • 2
    • 1
  • m

    Marc Knaup

    01/29/2019, 1:32 PM
    There are some functions I use so often they may be useful for the stdlib 🙂
    val <C : CharSequence> C.nonEmpty
    	get() = ifEmpty { null }
    
    val <CollectionType : Collection<*>> CollectionType.nonEmpty
    	get() = ifEmpty { null }
    
    val <Element> Array<Element>.nonEmpty
    	get() = ifEmpty { null }
    val actualNonEmptyString = inputString?.nonEmpty ?: error("is required")
    val actualNonEmptyList = inputList?.nonEmpty ?: error("is required")
    i
    a
    • 3
    • 6
  • m

    Marc Knaup

    01/30/2019, 9:15 AM
    We have
    hashMapOf()
    by now but no
    toHashMap()
    🙂
    d
    • 2
    • 1
  • g

    gregorbg

    02/09/2019, 2:49 PM
    Map<K, Set<T>>
    or
    Map<K, Iterable<T>>
    will also be perfectly fine, I'm mainly concerned about the grouping aspect and not the explicit return type
    p
    • 2
    • 2
  • r

    rrader

    02/14/2019, 4:06 PM
    What do you think about adding
    Option
    class? The use case https://youtrack.jetbrains.com/issue/KT-29026
    ➖ 5
    k
    m
    +2
    • 5
    • 6
  • a

    asad.awadia

    03/03/2019, 1:37 AM
    If i have a list of pairs (to and from) and want to get the distinct sorted pairs that occur the most what would be the most functional way of doing it? So
    [(1,2) , (3,4), (1,2)]
    should return
    [(1,2),(3,4)]
    i
    m
    o
    • 4
    • 18
  • p

    PHondogo

    03/03/2019, 7:30 AM
    Hello, were can i see changes to stdlib from version to version? I mean like in kotlin release notes. What was added or improved in stdlib...
    i
    • 2
    • 2
  • t

    Timmy

    03/08/2019, 7:47 PM
    In the kotlin stdlib the
    LinkedHashMap
    does not have the
    accessOrder
    property that the
    java.util.LinkedHashMap
    has. Is there a replacement if I want to use such a functionality, for example for as a LRU cache? Or should I look for a third party library for simple LRU caching (with kotlin multiplatform support)?
    j
    • 2
    • 2
  • j

    josephivie

    03/09/2019, 6:53 AM
    Why is it
    interface Comparator<T>
    instead of
    interface Comparator<in T>
    ? Like, I know theoretically you shouldn't have to specify that the
    T
    has
    in
    variance, but in common code errors will be shown if you do something like
    interface Sort<in T>: Comparator<T>
    , saying the
    T
    in
    Comparator
    is
    invariant
    .
    i
    • 2
    • 1
  • r

    rrader

    03/13/2019, 11:00 AM
    is there a function analogical to
    let
    but for empty strings
    someString?.let { calculate(it) }
    I need
    someString.doIfNotEmpty { calculate(it) }
    ?
    c
    k
    • 3
    • 2
  • a

    asad.awadia

    03/20/2019, 12:03 AM
    Can it be implemented as a dsl tho?
    g
    r
    +2
    • 5
    • 15
  • g

    gregorbg

    03/20/2019, 5:15 PM
    Just wondering, what is the rationale for the
    get
    operator returning
    Nullable?
    types for Maps but not for Lists? I understand that in a map, you may not know whether the key is set. But in a List, you may not know whether the index exists (i.e. the list is long enough) either??!
    s
    k
    c
    • 4
    • 13
  • a

    asad.awadia

    03/21/2019, 12:37 AM
    How can I write a lambda with a receiver such that I can write the following style DSL
    createHttpServer {
                options = myServerOptionsObjectVariableFromAboveSomewhere
                port = 8080
            }
    which should run effectively
    vertx().createHttpServer(options).listen(port)
    ?
    s
    • 2
    • 13
  • s

    spand

    03/25/2019, 12:48 PM
    Why does Kotlin have both
    Exception
    and
    RuntimeException
    ? I can sort of see a compatibility argument but both are present even in common
    i
    • 2
    • 1
  • p

    passsy

    03/25/2019, 4:36 PM
    Here's a question for the language designers: On on hand kotlins collections have extensions like
    toList
    or
    toMap
    . On the other hand
    asSequence
    and
    asIterable
    . From my testing the
    to
    methods copy the collection where the
    as
    methods create views on the data. Which means if the collections changes, the views also have access to the mutated data. Is this a not documented rule? Would it be "wrong" if one of my own
    asCustomList
    copies the data instead of creating a view? Should I call it
    toCustomList
    ?
    i
    • 2
    • 1
  • c

    chan

    03/31/2019, 8:33 AM
    Or I have to use pure Java annotation in this case, since it feels like Annotation Processor doesn't understand
    KClass<*>
    d
    • 2
    • 2
  • d

    Dias

    04/10/2019, 4:03 PM
    is it by design that fold and foldRight have the order of accumulator and current value switched?
    i
    • 2
    • 1
  • s

    Seri

    04/10/2019, 7:03 PM
    Is there a stdlib way to consecutively apply a list of functions to a single variable and their outputs?
    s
    • 2
    • 7
  • s

    Seri

    04/10/2019, 7:07 PM
    -.kt
    i
    • 2
    • 1
  • a

    asad.awadia

    04/16/2019, 12:20 PM
    Any ideas on what infix functions can be useful in a rest api? Looking for ideas to codify
    c
    r
    • 3
    • 7
  • l

    LeoColman

    04/16/2019, 4:48 PM
    Do you guys know if there's any particular reason for
    Char.isDigit
    to not have it's opposite
    Char.isNotDigit
    ?
    s
    i
    • 3
    • 13
  • m

    mkobit

    04/19/2019, 6:27 PM
    is there a simple way to window a
    Sequence
    based on attributes of the data? for example, if i have
    sequenceOf(1,2,3,5,6,8,10,14,15)
    i'd like to "merge" contiguous elements together into a sequence that is
    sequenceOf([1,2,3], [5,6], [8], [10], [14,15])
    i'd like to retain the lazy evaluation, such that
    [1,2,3]
    is yielded only when it is needed
    s
    l
    e
    • 4
    • 6
  • p

    Pere Casafont

    04/29/2019, 9:44 AM
    Is there a way to get a use of
    MutableCollection::plusAssign(Iterable)
    to compile without having assignment operators ambiguity error? Here an example that does not compile:
    val list = listOf(1, 2, 3)
    	var mutableList = mutableListOf(4, 5, 6)
    	mutableList += list
    g
    • 2
    • 4
Powered by Linen
Title
p

Pere Casafont

04/29/2019, 9:44 AM
Is there a way to get a use of
MutableCollection::plusAssign(Iterable)
to compile without having assignment operators ambiguity error? Here an example that does not compile:
val list = listOf(1, 2, 3)
	var mutableList = mutableListOf(4, 5, 6)
	mutableList += list
g

gildor

04/29/2019, 9:49 AM
Only if you replace
var
with
val
If you need
var
there, than use addAll instead:
mutableList.addAll(list)
p

Pere Casafont

04/29/2019, 10:07 AM
oh, yes I need var in my case, and now I understand what's up; thanks!
however, maybe it'd be nice if
plusAssign
had preference over
plus
+
assign
to avoid this odd situation
g

gildor

04/29/2019, 10:13 AM
mutableList += list
is acutally reassign mutableList, but (mutableList + list) returns List, so type is not compatible, so it’s not clear how you can solve it
View count: 1