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

    kushalp

    06/03/2020, 9:44 PM
    I have a function which returns
    IO<A>
    , where
    A
    is some
    enum
    having 3 different states:
    Complete
    ,
    Error
    and
    CustomError
    . I want to retry the function until either
    Complete
    is returned, or a duration exceeded condition is true. What is the best way to do that with
    IO
    ?
    s
    • 2
    • 1
  • c

    Clarence Dimitri Charles

    06/04/2020, 9:02 AM
    Hi guys, I would like to know if there is any example of using Arrow and Kotlin flow ? I searched on the web and couldn’t find anything useful.
    s
    • 2
    • 6
  • c

    Clarence Dimitri Charles

    06/04/2020, 9:40 AM
    Another question that I have. What is the recommended way of doing dependency injection ? Based on my research, there is the Reader monad based on a article written by Jorge Castillo. There is also this

    talk▾

    with Francisco Garcia. And also in the arrow documentation, you can do it using Typeclass. What is the recommended way of doing dependency injection ? what are the advantages of one method over the other ? If this question is not asked to the right channel, feel free to redirect me to the correct one
    p
    s
    +3
    • 6
    • 16
  • t

    tim

    06/04/2020, 5:09 PM
    Hey folks, I'm watching Scott Wlaschin's 2015 talk on Railway oriented programming. He mentions dead end functions which can be incorporated into a composition (tap and tee). Is there an equivalent in Arrow ... or is simply doing
    .map { someOp(); it }
    the approach?
    s
    h
    +2
    • 5
    • 73
  • p

    pakoito

    06/04/2020, 11:41 PM
    @Rachel??
    r
    j
    • 3
    • 4
  • m

    mattmoore

    06/04/2020, 11:53 PM
    @starke @pakoito Would this cover the logic safely? https://github.com/mattmoore/kotlin-playground/blob/master/src/test/kotlin/io/mattmoore/kotlin/playground/arrow/comprehensions/OptionComprehensionSpec.kt#L14
    👌🏼 1
    s
    • 2
    • 1
  • x

    Xuc Xiem

    06/05/2020, 1:55 AM
    Hi All, is there any way to remove the
    .k()
    as much as possible in the following example:
    val m = mapOf("a" to listOf(1, 2).k(), "b" to listOf(3).k()).k()
    val n = mapOf("a" to listOf(4).k(), "c" to listOf(5, 6).k()).k()
    val p = MapK.semigroup<String, ListK<Int>>(ListK.semigroup()).run { m + n }
    a
    p
    • 3
    • 10
  • x

    Xuc Xiem

    06/05/2020, 1:27 PM
    Hi All, another question: I'm using
    Either
    like this:
    fun f(): Either<Exception, A> = try {
      // do something
      Either.right(a)
    }
    catch (e: Exception) {
      Either.left(e)
    }
    Is that the correct way to use
    Either
    ? Is there anything more suitable than Either for that purpose (wrapping a value and catching all exceptions)?
    r
    s
    s
    • 4
    • 14
  • t

    tim

    06/06/2020, 3:29 PM
    Hello FP people 👋 I'm exploring applying FP/arrow across a micro service i'm building but I'm unsure what the best/right approach is in some areas. I've put together a short & simplified example which reflects my current thinking and I'd hugely appreciate any advice either 😂 in general but also specifically in terms of how to deal with the effects inside the Repo (should I use an Either, IO, Either.fx?!) and what that looks like?? I started looking at IO and .unsafeRunAsync, but the javadoc comment about never using it in production confused me as to how I actually get the block inside to execute?! Code snippet inside thread
    s
    p
    • 3
    • 28
  • x

    Xuc Xiem

    06/06/2020, 10:19 PM
    How to convert this list
    val eitherList: List<Either<Exception, String>> = TODO()
    to a
    List<String>
    ? Someone on StackOverflow (I think) suggested:
    eitherList
      .filterIsInstance<Either.Right<String>>()
      .fold(emptyList()) { acc, right -> right.fold({ acc }, { acc + it }) }
    Is there any better way?
    t
    • 2
    • 1
  • j

    julian

    06/09/2020, 5:55 PM
    I'm playing with functions. Here, the restriction I've set for myself is that f2 depends on f1 and f1 depends on E, but E must be supplied late, after the program has already been constructed. All that's fine, as far as it goes. I'm particularly interested in the function
    f3
    . It seems like there might be a named pattern for what it's doing. It kind of behaves like
    partially
    , except it defers the partial application till later. Then it partially applies to f2 the result of executing the deferred function (when that happens). If such a pattern exists, what's its name? Do helper functions already exist in Arrow to do this for me? Basically, is there a better way? Thanks much!
    Untitled
    r
    • 2
    • 7
  • t

    tim

    06/10/2020, 8:47 AM
    I'm half way through @raulraja's presentation to the Chicago Kotlin group and was curious when some of these features are available? Eg, from what I can tell
    @Coercion
    is not available now is it, if it is which package can I find it in?
    r
    j
    • 3
    • 23
  • p

    pakoito

    06/10/2020, 1:44 PM
    modify that file and send a PR 😄
    j
    • 2
    • 6
  • p

    pakoito

    06/10/2020, 3:54 PM
    the destructuring one may fail for some types because of ambiguity on the compiler
    c
    • 2
    • 1
  • t

    tim

    06/10/2020, 4:59 PM
    Sorry another newb question. I've have several functions that are called serially and only return a concrete value if they fail ... i've tried representing them as Option<Failure> but I'm unsure how to construct the comprehension on None. Is there an easy way to do this, or should I be using Either? If Either, what type should I use on the Right (Unit?)?
    b
    p
    • 3
    • 26
  • j

    julian

    06/10/2020, 7:25 PM
    @raulraja I was looking at this example of kotlin di that you wrote. I was wondering, if there was a requirement that
    Module.data
    or
    Module.domain
    be lazy evaluated, would there still be a way to have
    Module
    implement
    Data
    and
    Domain
    ?
    r
    • 2
    • 7
  • t

    tim

    06/11/2020, 4:53 PM
    Oh dear for some reason I thought the Arrow Academy presentation was starting in 10 minutes. Opps! will it be posted?
    a
    j
    +2
    • 5
    • 10
  • a

    Alexander Levin

    06/12/2020, 9:24 AM
    Hi everyone. Quick question - do you have high-res pictures for your Arrow modules (Arrow Core/Fx etc) Needed for presentation :)
    r
    • 2
    • 11
  • p

    PhBastiani

    06/12/2020, 1:40 PM
    Hello, This is my first attempt with the new ArrowFx DSL 🙂 https://gist.github.com/PhBastiani/9e494f7fd971848296914c775f052cbe No error/cancellation handling at the moment. Not sure that my tailrecursive
    copy
    method is the most idiomatic. I noticed a wrong proposal of the IDE: sometimes IntelliJ proposes to remove the
    suspend
    modifier when it is necessary 😕 Feedback appreciated !
    😍 2
    s
    j
    s
    • 4
    • 8
  • j

    Joram Visser

    06/13/2020, 11:00 PM
    With
    effectfulProgram: IO<E, A>
    I could do
    effectfulProgram.unsafeRunSync()
    to run the program from a none suspended context. (For example an endpoint in a framework without coroutines.) Now I am trying out the new Arrow Fx Coroutines lib and transformed my program to
    effectfulProgram: suspend () Either<E, A>
    . How do I run it? 😅
    a
    s
    • 3
    • 12
  • c

    carlos cdmp

    06/14/2020, 4:20 PM
    What is the correct way to solve this?. Usually I make these functions inline so context is not lost
    s
    • 2
    • 1
  • r

    raulraja

    06/15/2020, 12:55 PM
    https://twitter.com/raulraja/status/1272512506347565056
    :arrow: 6
    🙌 5
    g
    • 2
    • 2
  • r

    Robert

    06/15/2020, 1:09 PM
    Where can I read up on Coercion Projection and Liquid Types ?
    r
    i
    • 3
    • 7
  • c

    CLOVIS

    06/15/2020, 1:18 PM
    I have a use-case where I need to model objects that come from many different data sources, and they are not always the same. As a comparison, I could take calendar events. Some of my data sources let you subscribe to an event, some don't, but they all let you have a start/end date, etc. I think the ‘traditional' way would be something like:
    interface Event {
      val start: ...
      val end: ...
      val canSubscribe: Boolean
      suspend fun subscribe()
    }
    But that's a lot of boilerplate per feature, and since I want to learn Arrow, I'm thinking there must be a better way. What do you think of:
    interface Event {
      val start: ...
      val end: ...
      fun subsribe(): Either<UnsupportedOperationException, IO<Unit>>
    }
    p
    • 2
    • 65
  • j

    Jörg Winter

    06/17/2020, 12:25 PM
    Hi, regarding the (now merged) Arrow Fx Coroutines API, I would like to try it with 0.11.0-SNAPSHOT, specifically this monadic comprehension with Either:
    suspend fun either(): Either<PersistenceError, ProcessedUser> =
      Either.fx {
        val user = !fetchUser()
        val processed = !user.process()
        processed
      }
    .. so I added arrow-fx (SNAPSHOT) to my dependencies, but where does the bind-operator
    !
    come from ? IntelliJ doesn't seem to find it.
    s
    s
    r
    • 4
    • 20
  • s

    stojan

    06/17/2020, 4:19 PM
    curious to hear other opinions of Arrow users on this one -> https://github.com/arrow-kt/arrow-core/issues/114
    r
    f
    • 3
    • 19
  • s

    Srki Rakic

    06/17/2020, 4:44 PM
    Hi, I wanted to get some feedback on the approach for getting an output of a function that returns
    IO<Either<InvalidCommand, Command)>>
    as an input to a function that takes
    Command
    as a parameter and returns
    IO
    return EitherT.monad<ForIO, DomainError>(IO.monad()).fx.monad {
          val (command) = EitherT(commandFrom(commandType, commandString))
          val (eventRecord) = EitherT(commandHandler.handle(command).map { it.right() })
          eventRecord
        }.value().fix()
          .map { result -> result.fold({ Response.Error(it.toString()) }, { Response.Success(it) }) }
          .unsafeRunSync()
    Does this seem like the right approach?
    s
    • 2
    • 8
  • s

    Srki Rakic

    06/17/2020, 5:21 PM
    I guess the types just switched places
    inline fun <L, F> EitherT.Companion.monad(MF: Monad<F>): EitherTMonad<L, F>
    inline fun <L, F> EitherT.Companion.monad(MF: Monad<F>): EitherTMonad<L, F>
    s
    • 2
    • 2
  • t

    tim

    06/17/2020, 5:38 PM
    Hi all, I'm stuck and hoping someone can point me in the right direction 🙏 . I"m trying to do something like this:
    val numbers = listOf(1, 2, 3, 4)
    val strings = numbers.map { somethingThatReturnsEither(it) }
    
    // Here I'd like to map strings and put Lefts into one list and Rights into another list
    
    return Tuple2(failures, successes)
    Hopefully that makes sense. I could just do a forEach and put everything into lists manually, but I'm hoping there's an FP way here
    r
    • 2
    • 5
  • t

    Trond Engell

    06/18/2020, 10:50 AM
    Regarding use of
    NonFatal
    . I can understand if you really want to handle
    InterrupedException
    you might want to do that more explicitly, but what about errors that are not listed here (excluding subclasses)? Are they not fatal and to be thrown?
    fun NonFatal(t: Throwable): Boolean =
      when (t) {
        is VirtualMachineError, is ThreadDeath, is InterruptedException, is LinkageError -> false
        else -> true
      }
    s
    • 2
    • 20
Powered by Linen
Title
t

Trond Engell

06/18/2020, 10:50 AM
Regarding use of
NonFatal
. I can understand if you really want to handle
InterrupedException
you might want to do that more explicitly, but what about errors that are not listed here (excluding subclasses)? Are they not fatal and to be thrown?
fun NonFatal(t: Throwable): Boolean =
  when (t) {
    is VirtualMachineError, is ThreadDeath, is InterruptedException, is LinkageError -> false
    else -> true
  }
s

simon.vergauwen

06/18/2020, 10:56 AM
Yes, they’re considered non-fatal and will be thrown.
It’s used in a different manner. If you use
Either.catch
these fatal errors won’t be caught, but will continue to propagate.
So we use this as a predicate
t

Trond Engell

06/18/2020, 11:00 AM
Ah I see. So I should not use this predicate for non-async error-handling purposes?
I remember seeing the same in Scala, but never really understood its purpose.
s

simon.vergauwen

06/18/2020, 11:02 AM
Yes, it’s very common practice in Scala. And it’s actually good practice to do. If you’re using Arrow, or Cat in Scala this is already done for you out-of-the-box
So you shouldn’t worry about it. If you’re doing a lot of custom
try/catch
with
e: Throwable
then it’s a good idea to use this predicate as well. We typically do the following.
try { 
  donSomething()
} catch(e: Throwable) {
   ifError(e.nonFatalOrThrow())
}
t

Trond Engell

06/18/2020, 11:07 AM
I use something similar for Either:
fun <Result> Either.Companion.fromTry(block: () -> Result): Either<Throwable, Result> =
    try {
        block().right()
    } catch (throwable: Throwable) {
        throwable.nonFatalOrThrow().left()
    }
..as we have not introduced use of coroutines yet.
👍 1
Does that seem ok? I am just worrying that some Errors might slip through by not being thrown, like custom ones introduced by libraries or similar.
s

simon.vergauwen

06/18/2020, 11:14 AM
That’s perfect, and it’ll catch all exceptions except for “is VirtualMachineError, is ThreadDeath, is InterruptedException, is LinkageError”. Also custom onces introduced by libraries.
t

Trond Engell

06/18/2020, 11:21 AM
So you are saying that the custom ones will be catched, not thrown?
🤔 1
s

simon.vergauwen

06/18/2020, 11:24 AM
Don’t you want all
NonFatal
to be captured in
Left<Throwable>
?
throwable.nonFatalOrThrow()
returns a
NonFatal
exception, or it rethrows if the above predicate matches. That means that all exceptions, except for
VirtualMachineError
,
ThreadDeath
,
InterruptedException
&
LinkageError
will be rethrown. All other exceptions will be returned as
Left(exception)
.
t

Trond Engell

06/18/2020, 11:31 AM
Good question! 😄 I was wondering if what I really wanted was
Left<Exception>
and to throw all
Error
. In that case the predicate might not match all errors and I must do so manually. I am trying to wrap my head around this and I am unsure if this is good practice. I am sorry if this is not very Arrow-specific.
s

simon.vergauwen

06/18/2020, 11:34 AM
https://www.scala-lang.org/api/current/scala/util/control/NonFatal$.html
https://www.reddit.com/r/scala/comments/e85fdz/question_what_happens_when_your_code_catches_an/
https://twitter.com/djspiewak/status/1132747098783223809?s=20
t

Trond Engell

06/18/2020, 11:50 AM
Yes, I do not want to catch
Error
in any way. Just throw them and crash/exit application to avoid bad state. I just figured there must be a reason why the predicate is defined like this
is VirtualMachineError, is ThreadDeath, is InterruptedException, is LinkageError -> false
..and not like this
is Error, is InterruptedException -> false
It must mean that there is some
Error
that is not considered fatal.
But i will not continue to bore you with such details. Thanks for the help and hope you have an error-free evening!
👍 1
View count: 12