https://kotlinlang.org logo
Docs
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
functional
  • s

    simon.vergauwen

    12/23/2018, 12:53 PM
    fun tests(start: Int, end: Int): IntArray =
     (start until end).toList().toIntArray()
    h
    • 2
    • 5
  • r

    raulraja

    12/27/2018, 12:26 PM
    @benfleis The hidden Dragon is that the function is unsafe and nothing from it's type signature denotes that it's going to blow up if there are no elements. Safe versions of the same functions are:
    import arrow.data.NonEmptyList
    
    fun <A> NonEmptyList<A>.firstRest(): Pair<A, List<A>> =
      head to tail
    
    fun <A> Iterable<A>.firstRest(): Pair<A?, List<A>> =
      firstOrNull() to drop(1)
    b
    • 2
    • 3
  • p

    pakoito

    12/29/2018, 10:52 PM
    a review of Clean Architecture: http://parametri.city/blog/2018-12-23-language-oriented-software-engineering/index.html
    p
    p
    l
    • 4
    • 13
  • p

    pajatopmr

    12/31/2018, 8:37 AM
    So a big question in my mind early on is how Kotlin will play with other languages in the FP world, firstly Clojure being JVM based, and Scala on up to Haskell and other native FP languages.
    h
    b
    • 3
    • 3
  • r

    raulraja

    01/04/2019, 11:46 PM
    There is an entire conversation that is fairly recent about this same topic in #arrow
    p
    • 2
    • 3
  • r

    Rruiz

    01/23/2019, 4:42 PM
    Any ideas?
    s
    r
    • 3
    • 7
  • d

    Dalinar

    01/29/2019, 11:27 AM
    how do I make a map like the following? it is the result of adding 2 maps together ....
    mapA
    is a
    mapOf<String,AnsiColor>()
    and
    mapB<String,AnsiColor>
    needs to be mapped from
    set1<String>
    in the way that
    mapB
    entries are constructed from
    set1
    String
    element to
    AnsiColor.GREEN
    (this is a constant)
    r
    • 2
    • 7
  • d

    Dalinar

    02/13/2019, 3:19 PM
    CompletableFuture.supplyAsync(Supplier<Boolean>{
                        true
                    }, pool)
    so if I want the
    , pool
    then I need to use
    Supplier<>
    ? there is no way to get of it ? I'm asking because if you only supply one parameter then it is not necessary
    p
    • 2
    • 5
  • p

    pakoito

    02/21/2019, 6:35 AM
    you cannot have existentials in lambdas
    b
    • 2
    • 2
  • p

    pakoito

    02/21/2019, 6:36 AM
    you cannot have a lambda that’s generic for all <T>
    b
    • 2
    • 3
  • u

    Uberto Barbini

    04/06/2019, 2:58 PM
    Idle thought on Saturday: coming from Haskell, one thing that I'm missing in Kotlin is the let..in syntax Am I the only one that would like having something like this? (I've called it LETTING for clarity) A ideal constrain would be that the function should be pure, that is no access to external scope, like singletons, objects, public functions, java System. etc. etc.
    s
    t
    +2
    • 5
    • 36
  • r

    raulraja

    04/16/2019, 10:43 AM
    A simplified example with Arrow Function1.contramap
    Function1_contramap.kt
    👏 1
    p
    • 2
    • 2
  • a

    Alex

    06/13/2019, 9:00 PM
    Hey guys let me introduce myself and tell you why did I come in the first place: I'm 34, I have a small boy (15 months old!) and I've been developing software professionally for the last 4 years, mostly server side Java. I've been thinking what would be the best way to start learning FP since I started with Kotlin like a year ago. I'm always eager to learn and to improve my skills and knowledge. I couldn't find a trustworthy source to learn FP in Kotlin and given that Java is the language that I know the better and that Kotlin <- Java, I've bought the Functional Programming in Java book from Pierre Yves Saumont. Currently I've read half of the book. I've also been watching some videos from Kotlin, Arrow, 47 (I know some of you guys are here), category theory, etc. But it's a hard topic and I'm completely alone cause nobody knows what I'm talking about around me… Could you guys please shine a light on me? I mean, what do you think would be the best initial approach to learn FP effectively? What's in your opinion the best book/course to learn the fundamentals in Kotlin? I know about the red book of Scala but I would prefer to focus on Kotlin cause I really like it and I have real expectations of using it at work. So, where do you think is the best place to start practicing? Raul suggested me on Twitter that maybe I could contribute to some OSS so, how? Learn through pull requests? What do you tend to recommend to newcomers?
    m
    s
    +3
    • 6
    • 10
  • r

    raulraja

    06/13/2019, 9:07 PM
    @Alex Welcome! There is https://arrow-kt.io/ in Kotlin for all your FP needs whther beginning data types like Option, Either etc or more complex abstraction like type classes and the Functor hierarchy all accompanied with a purely functional effects system where you can compose pure programs in Kotlin and learn about working with IO and dealing with side effects. https://arrow-kt.io/docs/effects/fx/ Swing by the #arrow-kt and #arrow-contributors channel and feel free to ask any questions or suggest how you’d like to get started. Most newcomers learn by pull request or simply ask question in those channels and people chime in helping out frequently with code snippets and links to materials for follow up. The arrow docs also include extensive tutorials such as : https://arrow-kt.io/docs/patterns/error_handling/ that teach you how to do error handling with FP all the way to building concurrent programs https://arrow-kt.io/docs/effects/fx/async/#parallelization--concurrency
    🤘 1
    a
    r
    • 3
    • 2
  • p

    pakoito

    07/02/2019, 12:23 AM
    https://twitter.com/tomasruizlopez/status/1145729021675737088
    👏 7
    v
    • 2
    • 2
  • t

    tschuchort

    09/13/2019, 3:14 PM
    Can you give a code snippet how you would do it?
    p
    u
    +2
    • 5
    • 22
  • t

    thanh

    10/08/2019, 10:00 AM
    but I'm not sure It is the best I can get
    s
    • 2
    • 5
  • s

    simon.vergauwen

    10/08/2019, 10:13 AM
    @thanh what is the goal you’re trying to achieve?
    t
    c
    • 3
    • 13
  • p

    pawegio

    10/09/2019, 6:46 AM
    According to Kotlin coding conventions names of objects should start with an upper case letter and use the camel case (like classes), but you could also convert TVState to enum as it consists only of single-instance objects and then use uppercased letters.
    r
    • 2
    • 1
  • h

    Hexa

    10/17/2019, 8:46 PM
    is there a more functional way to write this code?
    fun main(args : Array<String>) {
        val input = Scanner(System.`in`)
        while (true) {
        
          var currentMax =0;
          var iWithCurrentMax =0;
            for (i in 0 until 8) {
                val mountainH = input.nextInt()
                
                if(mountainH >currentMax){
                   currentMax = mountainH;
                   iWithCurrentMax = i;
                }
            }
    
            println(iWithCurrentMax) 
        }
    }
    t
    p
    • 3
    • 8
  • h

    Hexa

    10/18/2019, 7:34 AM
    Thanks, there's so many different ways to do the same thing. It can be a bit confusing actually
    e
    t
    • 3
    • 6
  • m

    Mohamed Ibrahim

    10/22/2019, 7:26 AM
    how to access Kotlin lambda in Java code?
    g
    • 2
    • 1
  • r

    raulraja

    11/04/2019, 1:33 AM
    For those interested in union types in Kotlin https://twitter.com/raulraja/status/1191142263273009152?s=19
    ❤️ 4
    m
    • 2
    • 2
  • t

    tschuchort

    11/18/2019, 3:56 PM
    Do you think that with the advent of arrow-meta Kotlin will become as good at functional programming as Scala? Or is there still something missing that Scala has but we don't? I'm trying to learn Scala and it's only now that I can fully appreciate the syntactic simplicity of Kotlin 😄
    b
    i
    +5
    • 8
    • 45
  • t

    tschuchort

    11/20/2019, 12:07 PM
    You are just specifying implicit conversions. They are proofs in the sense that any function is a proof by the curry-howard isomorphism, but such proofs aren't worth much in a language with bottom values since they are a proof of any type.
    i
    j
    r
    • 4
    • 20
  • j

    javaru

    12/02/2019, 7:47 PM
    I want to handle exceptions in a
    map
    lambda by simply not mapping a value for when the exception happens? I"m currently adding
    null
    to the stream, then filtering out the nulls at the end. Is this the best and most idomatic way to handle this case?
    fun parseList(strings: Collection<String>): List<Foo>
    {
        return strings.stream().map { 
            try {
                parse(it)
            } catch (e: Exception) {
                null
            }
        }.toList().filterNotNull()
    }
    👍 1
    s
    e
    • 3
    • 5
  • t

    thanerian

    12/16/2019, 12:10 PM
    in Reactive Programming you should not store things out of the “chain”, if you want to sleep well on nights and avoid bizarre bugs related to dirty states
    k
    • 2
    • 2
  • c

    Codecriticon

    12/17/2019, 11:20 AM
    Hello, I am new to Kotlin and I would like to learn the concepts of functional and reactive programming, as well as Arrow. What books or resources do you recommend to learn? Thanks
    s
    • 2
    • 1
  • g

    gian

    12/18/2019, 10:26 AM
    Any chance to have something similar to an eta reduce in Kotlin?
    e
    • 2
    • 22
  • a

    Atanas Ladzhov

    12/19/2019, 6:35 PM
    Hey I am new to functional programming. Could you recommend some articles/books similar to Code Complete / Clean Code but for functional programming? What makes functional code better to understand / support in the long run?
    p
    s
    z
    • 4
    • 3
Powered by Linen
Title
a

Atanas Ladzhov

12/19/2019, 6:35 PM
Hey I am new to functional programming. Could you recommend some articles/books similar to Code Complete / Clean Code but for functional programming? What makes functional code better to understand / support in the long run?
p

PhBastiani

12/19/2019, 7:47 PM
'The Joy of Kotlin' is for me a good starting point...
s

Salves

12/21/2019, 3:51 PM
I am actually currently reading The Joy of Kotlin and like Philippe said I think is a good way to start to get introduced to functional 🙂
z

zhuinden

01/03/2020, 12:46 PM
Scala for Cats
View count: 4