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
getting-started
  • m

    menegatti

    07/20/2017, 11:08 AM
    data class <T> MyClass(...)
    should work
    m
    • 2
    • 14
  • d

    dio

    07/20/2017, 4:35 PM
    (I'm coming from clojure) is there a way to thread results in kotlin? Imagine I have
    fun foo(x: Int): Int
    fun bar(x: Int): Int
    fun baz(x: Int): Int
    I could
    baz(bar(foo(5)))
    but that starts to feel nested and gross, in clojure I can say
    (-> 5 foo bar baz)
    to feed the results of one function call into the next and un-nest my calls, I'm wondering if there's some equivalent ?
    h
    • 2
    • 5
  • d

    dio

    07/20/2017, 4:47 PM
    I found some non-std lib function composition that it looks like I can use... https://www.packtpub.com/mapt/book/application_development/9781787126367/5/ch05lvl1sec72/function-composition
    v
    • 2
    • 2
  • t

    techie01

    07/21/2017, 7:08 AM
    i have doubt in kotlin rangeTo() and downTo() are two functions if i apply reverse to 1 function i will get same result as another then why need two functions
    v
    p
    • 3
    • 7
  • m

    mohita

    07/21/2017, 9:27 AM
    Can anyone please explain this?
    e
    • 2
    • 3
  • m

    marior

    07/21/2017, 9:34 AM
    Hi guys, I am trying to make REST API with Spring in Kotlin using Android Studio and deploy to Tomcat server. Project works fine on IDE gradle server, but final .war file does´t run on Tomcat server. Any suggestions?
    n
    • 2
    • 5
  • d

    danielsan

    07/21/2017, 4:30 PM
    Where could I look up more advances use cases of Kotlin’s delegates / delegated properties? Are there some parts of the stblib where they are more heavily used? Or perhaps some 3rd party lib? Thanks!
    v
    a
    • 3
    • 5
  • m

    mat

    07/22/2017, 1:09 PM
    Advice on Learning Kotlin Android... What the take Learning it; - w/o java knowledge - w/ little java knowledge Thanks..
    a
    d
    • 3
    • 2
  • i

    ivano

    07/23/2017, 5:35 PM
    plus you know you are going to pile up memory in the Heap!
    v
    • 2
    • 3
  • r

    robsonj

    07/23/2017, 10:09 PM
    As someone new to Kotlin - c# dev. I was wondering what the preferred testing framework is for Kotlin please?
    i
    • 2
    • 3
  • j

    jkbbwr

    07/23/2017, 11:10 PM
    Have you set runtime retention
    n
    • 2
    • 1
  • d

    danneu

    07/23/2017, 11:36 PM
    is there a way to do something like
    when (v) { > 60 -> true }
    ?
    v
    • 2
    • 1
  • p

    pike

    07/24/2017, 2:44 AM
    is there a page for streams in kotlin? found a good SO on it
    👍 1
    v
    • 2
    • 2
  • t

    techie01

    07/24/2017, 6:43 AM
    can i use 100..10
    v
    • 2
    • 1
  • t

    techie01

    07/24/2017, 9:37 AM
    val a=null val b=null println(a==b) what is the o/p for this
    v
    • 2
    • 2
  • d

    damian

    07/24/2017, 7:32 PM
    The signature of the
    get
    operator is
    operator fun get(key: K): V?
    , where
    null
    is returned if the key is not found.
    k
    • 2
    • 1
  • k

    karelpeeters

    07/24/2017, 7:37 PM
    You can also do this this to avoid the unsafe !! operator using the elvis operator and `let`:
    fun main(args: Array<String>) {
        val map = mutableMapOf<String, Int>()
        val lst = mutableListOf<Int>()
        map["answer"] = 42
    
        for (arg in args) {
            map[arg]?.let { 
                lst.add(it)
            }
        }
    }
    b
    d
    r
    • 4
    • 26
  • r

    rrmen

    07/25/2017, 6:04 AM
    how can I understand higher order functions/lambas more?
    k
    d
    • 3
    • 3
  • t

    techie01

    07/25/2017, 6:11 AM
    i am getting short is deprecated then what to use now
    k
    • 2
    • 7
  • d

    dalexander

    07/25/2017, 1:09 PM
    It’s an extension function that can be called on a StringBuilder object, and which returns nothing. So if you have some
    val sb: StringBuilder = ...
    you could call
    sb.configure()
    .
    h
    • 2
    • 2
  • t

    techie01

    07/25/2017, 3:51 PM
    how to install kmongo
    t
    • 2
    • 3
  • t

    thisen

    07/27/2017, 8:33 PM
    What does
    !!
    operator do?
    💥 4
    b
    • 2
    • 1
  • d

    danneu

    07/28/2017, 1:31 AM
    you know, i kinda like swift's feature
    fun foo (_a a: Int) { return _a + _a }
    and thus
    foo(a = 42)
    where you can name an argument differently for the callsite
    b
    • 2
    • 1
  • k

    karelpeeters

    07/28/2017, 9:34 AM
    @hb2708 Please don't post the same thing in different channels (and even twice in the same channel), it just adds noise.
    h
    • 2
    • 4
  • t

    techie01

    07/28/2017, 10:48 AM
    how to use "let" and what is importance of it
    k
    d
    • 3
    • 2
  • h

    horse_badorties

    07/30/2017, 8:22 AM
    Hi there 🙂 why does Kotlin need
    Array
    in the first place? Why not use
    Collection
    and let the compiler optimize them away as JVM Arrays where possible?
    v
    d
    • 3
    • 21
  • z

    ziad

    07/30/2017, 11:21 AM
    Hi all, I keep getting "Unresolved reference" when writing unit tests for a class I'm actively developing even though the imports are there and intellij isn't complaining. If I build or hit run from Intellij, I get compilation errors. The errors only disappear of I build via gradle. What am I missing here?
    j
    • 2
    • 2
  • o

    oday

    08/01/2017, 10:43 AM
    is there a cool new flashy kotlin way to iterate over 2 lists of the same size in Kotlin?
    k
    m
    • 3
    • 21
  • o

    oday

    08/01/2017, 7:41 PM
    Handler().postDelayed(
            { Timber.d("Testing") }, 100)
    c
    f
    • 3
    • 11
  • r

    rockerhieu

    08/02/2017, 4:05 AM
    What is the shortest & safest way to add items from a subList to another list?
    srcList.subList(from, to).mapTo(destList) { convert(it) }
    subList
    may throw IndexOutOfBound, doesn't it?
    d
    • 2
    • 10
Powered by Linen
Title
r

rockerhieu

08/02/2017, 4:05 AM
What is the shortest & safest way to add items from a subList to another list?
srcList.subList(from, to).mapTo(destList) { convert(it) }
subList
may throw IndexOutOfBound, doesn't it?
d

diesieben07

08/02/2017, 7:19 AM
Not sure what you are trying to achieve, do you want
to
and
from
to be constrained to the list's size automatically if they are too large?
r

rockerhieu

08/02/2017, 7:30 AM
I just want to make the above line more concise without raising IndexOutOfBoundException
d

diesieben07

08/02/2017, 7:30 AM
What do you want to happen in case the indices are out of bounds though?
r

rockerhieu

08/02/2017, 7:30 AM
swallow the exception
d

diesieben07

08/02/2017, 7:31 AM
Yes, but what should the value of the expression be?
r

rockerhieu

08/02/2017, 7:31 AM
keep
from
, minimize
to
d

diesieben07

08/02/2017, 7:31 AM
And if
from
is out of bounds? 😄
r

rockerhieu

08/02/2017, 7:32 AM
ok, let me change it to
srcList.take(count)
d

diesieben07

08/02/2017, 7:32 AM
take
never throws 😉
🍺 1
r

rockerhieu

08/02/2017, 7:32 AM
nice, let me check 👍
View count: 1