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
arrow
  • y

    Youssef Shoaib [MOD]

    03/13/2021, 3:51 PM
    I wonder what the Arrow team is planning, however. I split the Functor interface into 2 btw because I originally had a version with the normal Functor interface but it then required an
    @with
    decorator for each pair of ins-and-outs, as in you'd need all of an
    @with(optionFunctor<Int, String>())
    , an
    @with(optionFunctor<String, String>())
    , an
    @with(optionFunctor<Unit, String>())
    , and an
    @with(optionFunctor<Any, String>())
    in the above example to make it work, and that multiples massively for each different type of input or output that you need to include, while with the splitting you only need to have a decorator for the sum of the number of inputs and outputs that you have. I think that probably having a huge amount of decorators will make the code look ugly even if it was generated automatically by the IDE, but I still have that original code if needed. Hopefully though you guys have already made a much much better encoding than this horrendous mess lol.
    s
    • 2
    • 8
  • a

    Anders Sveen

    03/15/2021, 11:59 AM
    Pretty new to both Arrow and functional programming, so excuse my confusion beforehand. 🙂 I have working code like the following:
    either {
      val id = parse(info).bind()
      val result = fetch(id).bind()
      Either.catch { ... }.mapLeft { ... }
    }
    And I am trying to get MDC logging to propagate through all of these calls. But it seems Arrow is dispatching on a new CoroutineContext so the MDCContext() in the original context is not propagated. Any pointers as to how I can get this to run with the "parent" context? IO.unsafeRunScoped seems relevant but not applicable... 🙂
    s
    • 2
    • 3
  • j

    Jörg Winter

    03/16/2021, 2:15 PM
    If understanding this (0.12 !) documentation correctly, there is no recommended special (arrow) coroutine builder for starting (for example) an either computation ? https://github.com/arrow-kt/arrow/blob/master/arrow-site/docs/docs/fx/README.md#executing-effectful-programs
    s
    • 2
    • 5
  • j

    Jörg Winter

    03/17/2021, 8:35 PM
    Thinking of the Monad instance of List, will there be such computation in arrow 0.12 (list comprehension) ?
    r
    y
    • 3
    • 6
  • p

    pakoito

    03/17/2021, 11:57 PM
    @simon.vergauwen I'd suggest replacing
    validated { }
    with something that takes a varargs of
    Validated
    values
    s
    o
    • 3
    • 5
  • c

    carbaj0

    03/20/2021, 6:04 AM
    i have a little issue
    Duplicate class arrow.core.ListKt found in modules arrow-core-data-0.12.0-SNAPSHOT (io.arrow-kt:arrow-core-data:0.12.0-SNAPSHOT:20210318.205637-108) and arrow-syntax-0.12.0-SNAPSHOT (io.arrow-kt:arrow-syntax:0.12.0-SNAPSHOT:20210318.205637-105)
    r
    • 2
    • 2
  • s

    stojan

    03/21/2021, 10:43 AM
    Result keep got updated https://github.com/Kotlin/KEEP/pull/244
    s
    k
    +2
    • 5
    • 12
  • b

    Benoît

    03/22/2021, 11:04 AM
    Hi everyone, I'm looking for inspiration. Do you know of any open-source app written with Arrow? I've found a few, but they are more proof-of-concepts/prototypes than actual apps
    j
    s
    • 3
    • 2
  • c

    CLOVIS

    03/22/2021, 6:42 PM
    What is the current state of Arrow for multiplatform?
    r
    c
    • 3
    • 9
  • f

    Fred Friis

    03/24/2021, 12:56 AM
    ^^^ I do understand the concept of instantiating an IO, building it up, and finally "running" it does that mean that, in the context of a jersey endpoint, it would have to look like this?
    class UserResource (private val userDao: UserDao) {
    
      @POST
      fun post(CreateUserRequest createUserRequest){
        return IO
          .fx {
            userDao.create()
        }
      }.runUnsafe something something
      .toEither()
      .fold({ left ->
        Response.serverError()
      },{ right ->
        Response.success(right)
      })
    }
    s
    i
    • 3
    • 4
  • j

    Jonathan Smith

    03/24/2021, 11:43 AM
    I really enjoyed this presentation on YouTube

    https://youtu.be/VOZZTSuDMFE▾

    and very interested in Arrow, but a scared off by some recent “Functional Programming” elitism I have seen in the Scala community. 1/ I really like type classes (I learned about them from tooling around in Haskell) and most of my substantial systems in the last ten years could have made good use of them. It’s generally a good idea to include them as part of the language (both Kotlin and Scala). 2/ I did write two 50,000+ line systems (server-side JVM), each with immutable models only. I did use shallow trait inheritance. I also used Akka Actors, each actor with a single var, for concurrency. (This was before typed actors.) All substantial business logic was part of the immutable classes. I thought I was doing functional programming in the immutable parts of the code (almost all of it) even without a library like Arrow or ScalaZ. My point is that functional programming is larger than and pre-dates category theory-style libraries. Before Scala I also wrote substantial systems in Standard ML, Common Lisp, and quite a lot of functional Scheme. Immutable and first class functions are good for programming even if not done with higher kinded types! 3/ I really worry that some Scala FP people, in pushing purity (puritanism?) have not convinced and tried to bring along the rest of the programming community by showing that these techniques are useful in context, but instead tried to look for converts who would reject prior learning and experience. I think this is a huge mistake and harmful not only to language communities but also turns many programmers away from what FP has to offer. It becomes more of an esoteric society than a useful way of writing systems. 4/ Programming languages and programming styles are tools for human being to think with. The only relevant question is do they help human beings think about and solve problems and communicate ideas to others. I’ve seen clean, easily understood FP programs and just as good OOP programs. I’ve seen really bad FP and OOP programs! We need to face that there are some domains that FP does not handle well even though many people have tried. Real world simulation models are still much better expressed as OOP (or mixed FP/OOP). Pure FP code for complex UI programming is really much harder to understand. (And yes, React is very impure in case you are wondering.) I like Kotlin a lot, including it’s embrace of multi-paradigm development. I hope Arrow can leave dogmatism at the door and ask more where can FP convincingly embraced as useful. It is important be willing to accept that FP is not the final programming paradigm and may not always be the best choice for actual human developers. 5/ How can you write substantial FP applications without functional (persistent) data structures? I’d imagine the alternative is to do a whole lot of copying and use much more memory for lack of shared data. I was pretty shocked that a good package of functional data types was not a key part of Arrow, or perhaps my impression is out of date? Can anyone recommend a library? Thanks!
    r
    b
    • 3
    • 3
  • b

    Benoît

    03/24/2021, 2:42 PM
    There's something I don't quiet understand, coroutines are an implementation of the Continuation monad, right? Then why is it recommended to use them instead of the IO monad?
    r
    k
    • 3
    • 16
  • f

    Fred Friis

    03/25/2021, 3:00 AM
    IO and suspend questions are so hot right now Thanks to the excellent reply to my previous question and reading around a bit more, I now feel like I understand IO/suspend better in practice But even as someone who's very fond of FP, I must admit I struggle to see the point a bit Like yes you can construct computations and map and filter and chain etc them in weird and wonderful ways but what's the practical actual use? I can make a strong case to FP skeptics for not using null, using result types instead of exceptions etc But I'd REALLY struggle to make any case at all for just coding vs creating an object of code and then calling .run
    s
    s
    +2
    • 5
    • 5
  • d

    Davide Giuseppe Farella

    03/25/2021, 1:10 PM
    Good morning, regarding
    Either
    , which is the best way to get left? Example
    // ok
    assertEquals(expectedResult, either.orNull())
    
    // how?
    assertEquals(expectedError, either.<leftOrNull()>)
    j
    a
    +5
    • 8
    • 15
  • p

    pajatopmr

    03/27/2021, 6:21 AM
    I am trying to learn FP using the Manning MEAP book Functional Programming in Kotlin. There is one exercise for which no answer is provided that I have a solution but it kind of seems yucky to me. How might an experienced FP Kotlin developer solve this:
    c
    r
    j
    • 4
    • 9
  • s

    seetha

    03/29/2021, 9:33 PM
    Hello Team, I am new to Arrow library. Have a question on 
    arrow.fx.coroutines.Schedule
      . Is there a way to get the number of attempt in the Either.catch
    Either.catch{
    	retry(Schedule.exponential(250.milliseconds)) {
    		evalOn(IOPool) {
    			//do something
    	  		incrementMetricSuccess(attempt)   -------> want to increment metric with the attempt it got successful
    		}
    	}
    }.mapLeft {
    	incrementMetricSuccess(attempt)    -------> want to increment metric with the attempt to fail
    }
    s
    s
    • 3
    • 6
  • d

    dnowak

    03/29/2021, 10:12 PM
    Hi, I have just noticed that
    .curried
    extension functions on functions is deprecated. Is there any replacement for that? I was using that method for
    dependency injection
    for functions. I assumed that
    currying
    is a basic operation in FP. Why it is being removed?
    r
    • 2
    • 12
  • c

    carbaj0

    03/31/2021, 1:13 PM
    also 0.13.0?
    👀 2
    :party-parrot: 7
    :kotlin-intensifies: 4
    s
    s
    c
    • 4
    • 8
  • t

    than_

    03/31/2021, 2:13 PM
    There seems to be a bug in optics generation in 0.13.0. it generates
    AppState(tuple.a, tuple.b, tuple.c, tuple.d, tuple.e)
    but Tuple5 doesn't have a, b, c... props anymore. it has first, second third... Is this just "we are in the middle of release, so things don't yet line up", or is it bug that slipped through?
    Untitled
    s
    r
    • 3
    • 10
  • b

    Brad M

    03/31/2021, 3:40 PM
    Not directly Arrow related, but someone might have had a similar issue. I’ve been switching our effectful functions over to
    suspend fun
    , but a library we use (
    java-dataloader
    ) requires functions with a CompletableFuture return type. How have folks been switching between
    CompletableFutures
    and
    suspend
    ?
    t
    • 2
    • 3
  • s

    Satyam Agarwal

    03/31/2021, 4:23 PM
    this doesn’t work :
    val (a: A, b: B) = parZip({ funA() }, { funB() }, ::Pair)
    but this works :
    val (a: A, b: B) = parZip({ funA() }, { funB() }) { a, b -> a to b }
    in v0.13.0
    j
    s
    • 3
    • 9
  • s

    Satyam Agarwal

    03/31/2021, 5:57 PM
    This fails in
    v0.13.0
    private fun methodThatThrows(): Either<Throwable, Unit> = Either.catch { throw CancellationException("") }
    
    @Test
    fun `test parTraverse`(): Unit = runBlocking {
        val result: Either<Throwable, Unit> = either {
            (1..20).parTraverse { methodThatThrows().bind() }
        }
    
        result shouldBe CancellationException("").left()
    }
    I cannot reach assertion, and throws as soon as
    methodThatThrows
    is called. cc: @simon.vergauwen (Sorry for tagging you on easter vacation, just want to make you aware 🙂 )
    j
    s
    • 3
    • 14
  • j

    julian

    03/31/2021, 10:09 PM
    0.13
    doesn't appear to have a
    Tuple3
    . Tuples start at
    Tuple4
    . Is this correct?
    t
    s
    • 3
    • 5
  • d

    Daniel Berg

    03/31/2021, 11:07 PM
    I'm upgrading from 0.11 to 0.13. Is there an updated document on traverse?
    s
    • 2
    • 5
  • m

    Maureen

    04/01/2021, 3:30 PM
    Here is the release post on 0.12 - 0.13.1. Thanks to everyone who contributed. @simon.vergauwen has detailed all the changes and migration guide here: https://www.47deg.com/blog/arrow-0.13.0-release/
    🎉 10
    :kotlin-intensifies: 17
    :arrow: 22
    👏 15
    🚀 5
    t
    • 2
    • 1
  • c

    CLOVIS

    04/01/2021, 9:57 PM
    The migration guide is very well written, thanks a lot ^^ I understand that higher kinded types are being removed because their integration in Kotlin is far from perfect, but do you think that decision is going to stand or are you thinking of reintroducing them sometime in the future when the language has changed to fit them better (eg. Arrow Meta, multiple receivers...)?
    s
    • 2
    • 3
  • j

    jem

    04/02/2021, 5:50 AM
    I’m having trouble continuing to use the
    Reader
    type after upgrading to 0.12.0. (MTL is still on 0.11.0 though). After this upgrade:
    -  val arrowFx = "io.arrow-kt:arrow-fx:0.10.5"
    -  val arrowMtlData = "io.arrow-kt:arrow-mtl-data:0.10.5"
    -  val arrowOptics = "io.arrow-kt:arrow-optics:0.10.5"
    +  val arrowFx = "io.arrow-kt:arrow-fx:0.12.0"
    +  val arrowMtlData = "io.arrow-kt:arrow-mtl-data:0.11.0"
    +  val arrowOptics = "io.arrow-kt:arrow-optics:0.12.0"
    I find that
    reader.run(thing).value()
    is no longer able to resolve
    .value()
    . How should it read now?
    .run(thing)
    is returning type
    Kind<ForId, T>
    ✅ 2
    s
    c
    +2
    • 5
    • 10
  • j

    jem

    04/02/2021, 6:48 AM
    --- Another migration question… With IO gone, how can I replicate this IO retry functionality?
    fun <T> IO<T>.retry(
      until: (T) -> Boolean = { true },
      additionalTimes: Int = 4,
      initialDelay: Duration = 500.milliseconds
    ): IO<T> {
      val schedule = Schedule
        .withMonad(IO.monad()) {
          exponential<Either<Throwable, T>>(initialDelay)
            .untilInput<Either<Throwable, T>> { it.exists(until) }
            .and(recurs(additionalTimes))
            .jittered(IO.monadDefer())
            .zipRight(identity())
        }
      return map<Either<Throwable, T>> { it.right() }
        .handleError { it.left() }
        .repeat(IO.concurrent(dispatchers()), schedule).fix()
        .flatMap {
          it.fold({ throwable -> IO.raiseError(throwable) }, { t -> IO.just(t) })
        }
    }
    ✅ 1
    s
    • 2
    • 3
  • n

    niltsiar

    04/02/2021, 9:01 AM
    Hi, I've seen the new changes for 0.12.0 and
    Either.catch
    with
    suspend
    functions is deprecated and the inline one is not accepting them. How should it be done with this new version?
    s
    • 2
    • 2
  • c

    Cody Mikol

    04/02/2021, 3:34 PM
    If you have an operation like this
    suspend fun foo() = either {
      val foo = !getFoo()
      val bar = !getBar()
      val foobar = !foobarFactory.make(foo, bar)
    }
    are
    foo
    and
    bar
    evaluated concurrently and then
    foobar
    once its dependencies have resolved? I’m trying to get a better overview of how arrow handles these suspended functions. Currently we are using
    either.eager
    , but I’d like to better understand the non-blocking
    either
    so I can benefit from that.
    s
    • 2
    • 5
Powered by Linen
Title
c

Cody Mikol

04/02/2021, 3:34 PM
If you have an operation like this
suspend fun foo() = either {
  val foo = !getFoo()
  val bar = !getBar()
  val foobar = !foobarFactory.make(foo, bar)
}
are
foo
and
bar
evaluated concurrently and then
foobar
once its dependencies have resolved? I’m trying to get a better overview of how arrow handles these suspended functions. Currently we are using
either.eager
, but I’d like to better understand the non-blocking
either
so I can benefit from that.
s

simon.vergauwen

04/02/2021, 3:38 PM
Hey @Cody Mikol, They're not evaluated concurrently, the program executes sequentially here just like
either.eager
does. The only difference between
either.eager
and
either
is that in the latter you can call
suspend fun
from inside the
{ }
block.
c

Cody Mikol

04/02/2021, 3:39 PM
That makes total sense, thank you 🙂
👍 1
s

simon.vergauwen

04/02/2021, 3:40 PM
If you want to make them run in parallel you can use Arrow Fx Coroutines inside
either { }
like so.
suspend fun foo() = either {
  val (foo, bar) = parZip(
    { getFoo().bind() },
    { getBar().bind() })
    { foo, bar -> Pair(foo, bar) }

  val foobar = !foobarFactory.make(foo, bar)
}
😍 1
c

Cody Mikol

04/02/2021, 4:04 PM
That is exactly what I’m looking for
Thanks for all your work on arrow, it has totally changed the way I think about writing programs
➕ 2
:arrow: 2
View count: 4