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

    than_

    08/21/2020, 9:40 AM
    Hi, it seems today's SNAPSHOT build didn't upload correctly to jfrog.
    Could not find arrow-fx-0.11.0-SNAPSHOT.jar (io.arrow-kt:arrow-fx:0.11.0-SNAPSHOT:20200821.081149-114).
    Searched in the following locations:
        <https://oss.jfrog.org/artifactory/oss-snapshot-local/io/arrow-kt/arrow-fx/0.11.0-SNAPSHOT/arrow-fx-0.11.0-20200821.081149-114.jar>
    Looking here that seems to be correct. Last snapshot has only pom, sources and javadoc files available.
    r
    • 2
    • 13
  • g

    Gopal S Akshintala

    08/21/2020, 11:14 AM
    For any docs, are both these URL patterns synonymous? - next.arrow-kt.io/docs and arrow-kt.io/docs/next... For example:
    <https://next.arrow-kt.io/docs/fx/async/>
    <https://arrow-kt.io/docs/next/fx/async/>
    r
    • 2
    • 2
  • g

    Gopal S Akshintala

    08/21/2020, 1:00 PM
    I hope
    parTraverse
    uses fibers underneath, how can I see that effect apart from measuring time (like by printing Fiber-id or something). I tried this example:
    @Test
        fun `parTraverse + blocking`() {
            val time = measureTimeMillis {
                runBlocking {
                    (1..20).parTraverse {
                        blockingWork(it)
                    }
                }
            }
            // 3s, multiple blocked bg threads
            println("Done in $time ms [${Thread.currentThread().name}]")
        }
    s
    • 2
    • 5
  • g

    Gopal S Akshintala

    08/22/2020, 8:39 AM
    Hi! Probably a basic question, about
    either{}
    DSL. The return type of this is
    Either<E,A>
    , so I understand one way the composition trips to
    left
    is -- one of the functions inside returns an either in
    left
    I am unable to figure out how to explicitly return an either in
    left
    from within the block. For example:
    val result: Either<String, String> = either { // This casts the side-effect function into a suspend function.
                val id = !getSomethingFromDb(true)
                val data = !getSomethingElseFromNetwork(id)
               val either = if (data.isEmpty()) {
                   // vvv how to return either on left
                   !"SOME_CUSTOM_ERROR".raiseError()
               } else data.right()
               either
            }
    I understand for a case like this where I have this requirement on the last step, I can return from outside the block, but just curious how to short-circuit from the middle of the block?
    s
    • 2
    • 13
  • j

    julian

    08/23/2020, 6:48 PM
    With
    Option
    map2
    , one provides a lambda that handles the case where both values are
    Some
    . But what if one wants to provide a lambda for all four possible cases? I can do this from scratch. But I wondered if there's a higher order function in Arrow that's already designed for this.
    r
    d
    j
    • 4
    • 4
  • g

    Gopal S Akshintala

    08/24/2020, 4:03 AM
    Hi! can someone pls help me if I am using
    IOPool
    in conjunction with
    parTraverse
    in the right way? I couldn't find any documentation about it.
    @Test
        fun `IODispatcher + parTraverse + blocking`() {
            val time = measureTimeMillis {
                runBlocking {
                    evalOn(IODispatchers.IOPool) {
                        (1..20).parTraverse {
                            blockingWork(it)
                        }
                    }
                }
            }
            println("Done in $time ms [${Thread.currentThread().name}]")
        }
    
     private fun blockingWork(i: Int) {
            Thread.sleep(1000)
            println("Work $i done [${Thread.currentThread().name}]")
        }
    s
    • 2
    • 10
  • a

    Alexander Schell

    08/25/2020, 8:13 AM
    Good Morning! 🙂 Would somebody please be so kind to explain to me what the idea is behind Invariant's imap function? I'm more than a little bit puzzled about it's sginature. Thanks!
    s
    t
    • 3
    • 17
  • h

    HieiJ

    08/26/2020, 12:23 PM
    Hi, just playing with 0.11.0-SNAPSHOT... I see that Either.fx() is marked as deprecated. I know you are working in order to use the continuations solution not only for IO but for every monad, but is it going to be included in 0.11? If not, what will be the right way to manage comprehension-like syntax for either in 0.11?
    a
    k
    • 3
    • 4
  • i

    isto

    08/27/2020, 12:27 PM
    `Apply`'s
    mapN
    takes in at most 10 params (0.10.5), any tips how to workaround a case where there's more than 10
    p
    j
    • 3
    • 6
  • j

    julian

    08/28/2020, 4:05 AM
    I was reading source for
    State
    and saw this:
    fun <S, T, P1, R> State<S, T>.map(sx: State<S, P1>, f: (T, P1) -> R): State<S, R> =
      flatMap(IdBimonad) { t -> sx.map { x -> f(t, x) } }.fix()
    What is
    IdBimonad
    doing? (I read the docs available for
    BiMonad
    , but I'm still mystified.)
    i
    j
    • 3
    • 29
  • m

    Maciek

    08/28/2020, 11:49 AM
    I'm building a service with a retrofit. Is there an adapter to use
    Either
    as return type? Or is there some different suggested way of handling retrofit calls?
    s
    y
    j
    • 4
    • 10
  • j

    Johan Basson

    08/28/2020, 1:00 PM
    What is the correct way of logging when using arrow? Would one do: IO { logger.info("Hallo world") } ?
    p
    p
    • 3
    • 5
  • j

    julian

    08/28/2020, 5:43 PM
    When I check out
    arrow-core
    and run
    ./gradlew build
    , I get this error:
    FAILURE: Build failed with an exception.
    
    * Where:
    Build file '/Users/bayo/dev/arrow-core/build.gradle' line: 2
    
    * What went wrong:
    A problem occurred evaluating root project 'arrow-core-lib'.
    > Could not read '<https://raw.githubusercontent.com/arrow-kt/arrow/master/setup.gradle>' as it does not exist.
    What am I doing wrong? I just want to be able to open and explore the source with all the features of IntelliJ that assist that to be available.
    j
    r
    • 3
    • 13
  • z

    zero_coding

    08/29/2020, 3:59 PM
    How to solve such as scenario with arrow?
    fun Program.handleRead(id: String?): UserMapper =
        id?.let {
            UUID.fromString(it)?.let { uuid ->
                queries.read(uuid)?.toMapper()
            } ?: throw UUIDWrongFormatException()
        } ?: throw UserNotFoundException()
    y
    p
    i
    • 4
    • 8
  • z

    zero_coding

    08/30/2020, 1:15 PM
    Hi all I am using Kotlin script in gradle and would like to enable arrow-core. On the website, it describes https://arrow-kt.io/docs/quickstart/setup/#arrow-core but how to enable it in Kotlin script
    plugins {
        application
        kotlin("jvm") version "1.4.0"
        ?????
    }
    Would be nice if someone could help.
    a
    r
    • 3
    • 2
  • z

    zero_coding

    08/30/2020, 4:33 PM
    Hi all Coming to Scala and would like to know, how to define the following tagless interface in Kotlin with Arrow:
    trait GenderQuery[F[_]] {
    
      def findAll: F[Genders]
    
    }
    r
    • 2
    • 9
  • c

    CLOVIS

    08/31/2020, 1:27 PM
    Is there a wiki article that explains how to do: “I have two different classes that have the same function, but they were written by two different people and therefore don't implement a common interface. How can I write an extension interface so that I can then use polymorphism on these classes” From reading the wiki and discussing here, I understand that this is pretty much spot on what typeclasses are used for, but I'm not really sure what the syntax would look like (especially with Arrow Meta). I think it could be very convenient if there was a wiki page with small self-contained use-cases like this one, what do you think?
    r
    • 2
    • 6
  • j

    Johan Basson

    09/01/2020, 9:43 AM
    Hi all I have this function:
    typealias GetCustomer = (config: Config, domain: Domain) -> IO<Either<ApiError, Option<CustomerDetails>>>
    which will do a rest call to get CustomerDetails Reading the arrow documentation i managed to get this:
    val io = getCustomer(cloudConfig, domain).repeat(IO.concurrent(), Schedule.doWhile(IO.monad()) { it.isEmpty()})
    val maybeCustomer = EitherT(io).bind()
    How can i add exponential backoff with a max retries of 10 starting with a 1 second delay?
    j
    • 2
    • 4
  • r

    Ryan Benasutti

    09/01/2020, 10:16 PM
    Are there
    suspend
    versions of
    map
    and
    flatMap
    for
    Either
    ?
    j
    • 2
    • 1
  • g

    gas

    09/02/2020, 8:02 AM
    Is this a known issue?
    r
    • 2
    • 12
  • r

    rcd27

    09/02/2020, 8:09 AM
    Hello everyone. I'm now reading "Category Theory for Programmers" by Bartosz Milewski and need some mentoring in this, in part of "Challenges" (after each chapter there are some tasks, need help in treating/coding them correct in Kotlin language)
    r
    • 2
    • 2
  • j

    Johan Basson

    09/02/2020, 9:04 AM
    Hi all, where can i get an example of "IO.repeatOrElse" ?
    r
    • 2
    • 4
  • t

    than_

    09/02/2020, 10:52 AM
    Hi, since Option got deprecated, is there an alternative for FunctorFilters filterMap? What is the preferred way to use optics with nullables now?
    r
    • 2
    • 3
  • y

    Youssef Shoaib [MOD]

    09/05/2020, 7:28 PM
    This is more of a general fp-question, but this seems like a good place to ask it. Why does Applicative exist instead of just apply? This might sound weird, but can't
    just
    be implemented for any Functor by using an instance of that functor and calling map on it with a function that disregards it's results and just returns whatever value was passed in. So something like this
    inline fun <reified F,A,B> Kind<F,A>.Companion.just(value: B): Kind<F,B> {
        return getSomeStaticValueForFunctor<F>().map { B }
    }
    So instead of having Applicative, couldn't there be just a
    FunctorWithStaticInstance
    that then
    Apply
    inherits from (and by extension
    Monad
    also inherits from). Additonally, the docs mention that some classes can implement
    Apply
    but not
    Applicative
    , but isn't it guaranteed that every typeclass in general will have an instance? so then with a pretty simple implementation you could probably produce a
    Functor<Unit>
    that will be a
    val
    on
    FunctorWithStaticInstance
    . Or maybe even every functor could just have a static instance by default. Maybe then you could even have
    just
    on
    Functor
    itself. I'm sure that there's definitely something wrong with my reasoning, but I honestly cannot figure it out.
    r
    • 2
    • 13
  • h

    Hiosdra

    09/06/2020, 7:31 PM
    Hi, for using arrow-core-retrofit integration on 0.11.0-SNAPSHOT I have: (left is Unit bec. I will never have body there)
    @GET("foo")
      suspend fun getFoo(
        @Query("param") param: String
      ): Either<Unit, FooDto>
    and helper (ideally unnecessary) method:
    fun notGonnaHappenError(): Throwable = TODO()
    How to return
    Either<DomainError, FooDto>
    ? I have this method:
    private suspend fun getFoo(param: Bar): Either<DomainError, FooDto> =
        Either.catch { client.getFoo(param.value).mapLeft { notGonnaHappenError() } }
          .flatten()
          .mapLeft { DomainError(it) }
    But I think it’s not as beautiful as it can be…
    s
    • 2
    • 4
  • s

    Sagar Suri

    09/07/2020, 2:32 AM
    Hey Team, I have seen kotlin and Arrow courses on 47degree website. But those are not available for individuals. Will it available anytime soon? Thanks
    r
    m
    • 3
    • 3
  • g

    genovich

    09/07/2020, 10:18 AM
    Hi, I try to serialize
    Either
    to json using Jackson, and I faced with issue: when I try to serialize
    Either
    instance - everything is ok, but when I try to serialize some wrapper-class with
    Either
    I’ve got an exception. For Gson behavior changes: it’s returning null.
    println(toJson("x".right()))
    // { "value" : "x" }
    
    data class Wrapper(val value: Either<Throwable, String>)
    println(toJson(Wrapper("x".right())))
    // java.lang.RuntimeException: com.fasterxml.jackson.databind.JsonMappingException: Index: 0 (through reference chain: Test$test$Wrapper["value"])
    // null (for Gson)
    I’m using custom serializer which converts
    Either.Right
    to
    { "value" : … }
    and
    Either.Left
    to
    { "error": … }
    , but when I’m removing it, behavior doesn’t change.
    p
    • 2
    • 2
  • j

    Jörg Winter

    09/07/2020, 3:29 PM
    🎉 switching from
    IOs parTraverse
    to
    fx-coroutines parTraverse
    seem to gives me about 20 to 26 percent performance gain ! ...to authors & experienced users of fx-coroutines: is that your observation too ? (and for sure it is much more concise and elegant 🙂 )
    🎉 6
    t
    y
    +2
    • 5
    • 11
  • c

    CLOVIS

    09/07/2020, 9:35 PM
    Hi! After learning a lot about this, I'm considering picking up Haskell. Do you have any recommendations on how to go with that for someone that is used to JetBrains IDEs and such tooling?
    m
    • 2
    • 3
  • t

    Tristan Blakers

    09/08/2020, 1:10 AM
    hi, I have the need to call a suspending function from Either.flatMap() I understand the recommendation to use IO in this case, however I'm not a big fan of using Throwable as the error type, rather than my own sealed class. Is there anything particularly wrong with working around this via an extension function? i.e.
    suspend fun <A, B, C> EitherOf<A, B>.flatMapSuspend(f: suspend (B) -> Either<A, C>): Either<A, C> =
        fix().let {
            when (it) {
                is Either.Right -> f(it.b)
                is Either.Left -> it
            }
        }
    y
    t
    • 3
    • 3
Powered by Linen
Title
t

Tristan Blakers

09/08/2020, 1:10 AM
hi, I have the need to call a suspending function from Either.flatMap() I understand the recommendation to use IO in this case, however I'm not a big fan of using Throwable as the error type, rather than my own sealed class. Is there anything particularly wrong with working around this via an extension function? i.e.
suspend fun <A, B, C> EitherOf<A, B>.flatMapSuspend(f: suspend (B) -> Either<A, C>): Either<A, C> =
    fix().let {
        when (it) {
            is Either.Right -> f(it.b)
            is Either.Left -> it
        }
    }
y

Youssef Shoaib [MOD]

09/08/2020, 2:32 PM
You could probably use an IO of Either with a transformer
t

than_

09/08/2020, 3:35 PM
either{
    someEither.bind().let{ someSuspendingStuff(it) }.bind()
}
this works 🙂
👍 1
t

Tristan Blakers

09/11/2020, 9:11 PM
thank you - the new either {} syntax is wonderful
:arrow: 2
View count: 4