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

    voddan

    02/13/2018, 9:05 AM
    Tried to use the
    replace
    function
    inline fun CharSequence.replace(regex: Regex,  noinline transform: (MatchResult) -> CharSequence): String
    And found out that I can't easily destructure the lambda parameter and have to use
    MatchResult.destructured
    instead http://kotlinlang.org/api/latest/jvm/stdlib/kotlin.text/-match-result/destructured.html Why the most intuitive usage
    text.replace(Regex("(\\d+)(\\w+)")) { (digits, letters) -> ""}
    was not supported? What's the point of having a separate wrapper for desctructuring? http://kotlinlang.org/api/latest/jvm/stdlib/kotlin.text/-match-result/-destructured/index.html Shouldn't we add
    componentN()
    extension function to
    MatchResult
    ?
    g
    • 2
    • 1
  • i

    ilya.gorbunov

    02/13/2018, 2:38 PM
    @voddan
    What's the point of having a separate wrapper for desctructuring?
    The wrapper changes the group numbering, so that
    component1
    corresponds to the group with index 1, rather than 0. We had experimented with the design when
    MatchResult
    can be destructured immediately, but found that very confusing https://discuss.kotlinlang.org/t/public-review-of-the-standard-library-apis-closed/1362/76
    👍 1
    v
    • 2
    • 2
  • i

    ilya.gorbunov

    02/13/2018, 2:59 PM
    📣📣📣 A quick survey about immutable collections. 📣📣📣 If you had the immutable collections in Kotlin, what would you use them for? We need to gather some use cases to better understand which implementations of immutable collections should be provided/should be default.
    h
    k
    +3
    • 6
    • 7
  • k

    kevinmost

    02/15/2018, 3:11 PM
    I think by far, the most common use-case is going to be combining collections (either a union of two sets, or concatenating two lists)
    ➕ 1
    k
    • 2
    • 1
  • w

    wakingrufus

    02/16/2018, 3:08 AM
    Would a PR for adding a pow() extension for BigDecimal be welcome in MathJvm?
    • 1
    • 1
  • m

    mg6maciej

    02/26/2018, 5:13 PM
    What's the canonical way of zipping 3 lists?
    a
    • 2
    • 1
  • r

    raulraja

    02/26/2018, 7:07 PM
    @mg6maciej Zipping lists is IMO better when preserving type information but it requires boilerplate for the different arities:
    data class Tuple3<A, B, C>(val a: A, val b: B, val c: C)
    
    fun <A, B, C> List<A>.zip(g: List<B>, h: List<C>): List<Tuple3<A, B, C>> =
      this.zip(g).zip(h).map { (ab, c) ->
        val (a, b) = ab
        Tuple3(a, b, c)
      }
    
    fun main (args: Array<String>) {
    
        val l1: List<Int> = listOf(1, 2, 3)
        val l2: List<Char> = listOf('1', '2', '3')
        val l3: List<String> = listOf("1", "2", "3")
    
        val zipped: List<Tuple3<Int, Char, String>> = l1.zip(l2, l3)
    
        println(zipped) //[Tuple3(a=1, b=1, c=1), Tuple3(a=2, b=2, c=2), Tuple3(a=3, b=3, c=3)]
    
    }
    g
    • 2
    • 4
  • j

    jw

    02/27/2018, 1:34 AM
    you should also add
    func: (A, B, C) -> T = ::Triple
    if you can
    a
    • 2
    • 3
  • s

    stepango

    03/03/2018, 8:41 AM
    what's
    kotlin.internal.contracts
    is used for?
    a
    a
    g
    • 4
    • 4
  • a

    Aregev2

    03/06/2018, 9:03 AM
    When random will be added to stdlib
    h
    • 2
    • 2
  • j

    jw

    03/06/2018, 11:45 PM
    and to answer your second question: yes they are, but they also enable a unified API that can be ported to other platforms which do not have
    java.lang.Math
    (which is required for #multiplatform)
    d
    • 2
    • 1
  • a

    asad.awadia

    03/06/2018, 11:48 PM
    for(x in 0 until prices.size) {
                if(prices[x]<min) min=prices[x]
                else max=Math.max(max,prices[x]-min)
            }
    on leetcode took 332ms
    g
    • 2
    • 1
  • m

    marcinmoskala

    03/07/2018, 9:48 AM
    @asad.awadia Why not:
    val minPrize = prices.min()
    val maxProfit = prices.min() - minPrize
    ?
    a
    • 2
    • 1
  • e

    elect

    03/07/2018, 10:35 AM
    example, I have a geometry lib (https://github.com/kotlin-graphics/glm), where I'd like to write
    val color = Vec4()
    val vertexData = floatArrayOf(*color)
    a
    • 2
    • 5
  • m

    mg6maciej

    03/07/2018, 10:56 AM
    Should I use
    someMap.filterValues { it != null }.mapValues { it.value as Any }
    or is there anything like
    someList.filterNotNull()
    for `Map`s?
    i
    k
    m
    • 4
    • 7
  • d

    diesieben07

    03/08/2018, 11:16 PM
    Using
    org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.2.30
    I cannot use
    use
    on
    AutoCloseable
    , is that correct? How can I "use" an
    AutoCloseable
    ?
    i
    • 2
    • 13
  • h

    holgerbrandl

    03/15/2018, 1:33 PM
    Or simply
    boolarr.contains(true)
    . An IDE warning here would be nice indeed.
    m
    • 2
    • 1
  • h

    holgerbrandl

    03/15/2018, 2:00 PM
    Is there a ticket for it?
    i
    • 2
    • 2
  • r

    rrader

    03/19/2018, 10:44 AM
    Is there a way to disable not null checks? https://stackoverflow.com/questions/49360740/disable-not-null-checks-in-kotlin
    d
    g
    s
    • 4
    • 15
  • g

    groostav

    03/19/2018, 10:13 PM
    hey gents, regarding list/set/sequence extension functions, is there a discussion about including those same extension functions that take custom equality comparators? EG:
    public infix fun <T> Iterable<T>.intersect(other: Iterable<T>): Set<T> {
        val set = this.toMutableSet()
        set.retainAll(other)
        return set
    }
    
    public fun <T, C> Iterable<T>.intersect(other: Iterable<T>, comparator: (T, T) -> Boolean) { //...
    i
    • 2
    • 2
  • h

    holgerbrandl

    04/04/2018, 2:49 PM
    Yes. But
    kotlin.Throwable
    isn’t extending
    java.lang.Throwable
    . Also the docs are not too helpful: https://kotlinlang.org/docs/reference/exceptions.html states that
    All exception classes in Kotlin are descendants of the class Throwable
    but I could not find any example in the stdlib. E.g. see kotlin.KotlinNullPointerException as a counter-example.
    i
    • 2
    • 6
  • a

    Aregev2

    04/04/2018, 3:44 PM
    Some ideas to make std better: file I/O functionalities Generate random number (rand()) Make more collections: SortedSet, SortedMap, LinkedList, TreeMap. Make constructors for Map and Set (interfaces) Native implementation of List.shuffle
    g
    k
    • 3
    • 4
  • a

    Aregev2

    04/04/2018, 10:30 PM
    Got more ideas: Theads. Pointers (as mentioned in #kotlin-native, It will be a great addition) And @ilya.gorbunov, in the brackets we can use Pair() or A to B similar to mapOf()
    g
    • 2
    • 1
  • b

    brescia123

    04/16/2018, 8:29 AM
    Hi everyone, I was reasoning about the semantic meanining of the stdlib’s
    public inline fun <T> Iterable<T>.all(predicate: (T) -> Boolean): Boolean
    with my colleagues and I realized that a lot of them have different intuitive expectations about the output of the function when called on an empty list. Can someone provide some insights about the decision of make it return
    true
    if the list is empty? Thanks!
    m
    • 2
    • 1
  • d

    dimsuz

    04/18/2018, 2:31 PM
    Hi! How do I replace last space in sting:
    one two three
    ->
    one two\nthree
    . There's
    replaceFirst
    , but no
    replaceLast
    d
    h
    • 3
    • 3
  • d

    Dave Leeds

    04/19/2018, 3:14 AM
    Hello! I'm doing some research on type aliases, so I'm looking through the standard library to see how
    typealias
    is used. I've found that it's most frequently used to map some common classes (e.g., exceptions,
    StringBuilder
    ,
    ArrayList
    ,
    Serializable
    ) to the corresponding Java classes. I was curious if @ilya.gorbunov or someone else at JB can fill me in on the purpose of these particular aliases in the standard library. Are they intended to save on imports (e.g., no need to import
    java.util.*
    if
    ArrayList
    is found in
    kotlin.collections
    )? Or to give Kotlin the flexibility to expand on the interface of those classes in the future? Or something else? Thanks!
    g
    • 2
    • 5
  • k

    kz

    04/26/2018, 3:07 PM
    (This is probably not the right channel but I'm not sure what would be) How does the Kotlin compiler decide when the class generated for a lambda includes the
    this
    reference? I'm using Apache Spark and my jobs is failing due to the task not being serializable because one of my lambda's generated class includes the
    SparkJob
    reference (which I don't want
    Serializable
    ). The reference is included as a class field even though it's not actually accessed. Then in my other spark jobs I have plenty other lambdas that also don't access the
    this
    reference and properly do not have that code generated.
    a
    d
    • 3
    • 8
  • n

    nfrankel

    04/28/2018, 5:45 PM
    https://stackoverflow.com/questions/50076861/how-can-i-create-a-map-with-every-two-items-in-a-list-in-kotlin/50079322?stw=2#50079322
    i
    • 2
    • 2
  • v

    voddan

    06/05/2018, 11:21 AM
    Such implicit argument conversion will cause huge performance issues. When I write
    5.pow(4)
    I expect it to perform the most efficient way, using the information that both arguments are integers
    g
    k
    • 3
    • 6
  • a

    Aregev2

    06/14/2018, 5:26 AM
    SortedSet/Map TreeSet/Map
    v
    • 2
    • 2
Powered by Linen
Title
a

Aregev2

06/14/2018, 5:26 AM
SortedSet/Map TreeSet/Map
v

voddan

06/14/2018, 7:15 AM
AFAIK those (and above) are easily available on JVM. What platform are you on? Or do you mean multiplatform?
a

Aregev2

06/14/2018, 7:18 AM
I mean multiplatform, will be nice to see it on native for example
View count: 2