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

    Stian N

    04/03/2020, 9:00 AM
    How do you properly mock an Either<> response? I have a function where I want to test the Left case, but using mockK this way gives me a Right(b=Left(a....))
    every { someFunction(any()) } answers { Either.left("Go left")) }
    s
    s
    • 3
    • 11
  • m

    max.cruz

    04/03/2020, 1:50 PM
    Hi everyone. I’m having this error in an Android build using Arrow 0.10.5
    Warning: arrow.core.extensions.ListKCrosswalk$crosswalk$1$2$1$1: can't find referenced class arrow.core.extensions.ListKCrosswalk$crosswalk$1$2
    Warning: arrow.core.extensions.ListKCrosswalk$crosswalk$1$2$1$1: can't find referenced class arrow.core.extensions.ListKCrosswalk$crosswalk$1$2
    I found this closed issue: https://github.com/arrow-kt/arrow/issues/807 Someone know if there is a workaround for this problem?
    s
    a
    • 3
    • 8
  • j

    Jake

    04/03/2020, 11:46 PM
    I guess I had glossed over fork() when reading about Queues / IO. I did read the article. I was just making sure I hadn't missed something in the arrow world before going with suspended() / coroutine scopes. Thanks for the help!
    r
    • 2
    • 1
  • g

    Gopal S Akshintala

    04/04/2020, 12:26 PM
    Slide-deck for my online talk about Arrow at Kotlin User Group, Hyderabad. Thanks for this Channel and Community for helping me 🙂 https://speakerdeck.com/gopalakshintala/template-oriented-programming-top-to-ship-faster
    🙌 1
    📺 1
    😍 5
    r
    • 2
    • 3
  • t

    than_

    04/06/2020, 5:12 PM
    I'm I missing something, or current implementation of Queue cannot be functor?
    p
    • 2
    • 7
  • h

    herlevsen

    04/07/2020, 11:33 AM
    Hi. I’m trying to do monad comprehension for
    OptionT
    . My stack is
    IO<Option<User>>
    . I cant figure out what to import to get
    OptionT.fx.
    I have tried importing arrow.mtl.extensions.fx like described here: https://arrow-kt.io/docs/0.10/arrow/mtl/optiont/, but that doesn’t work
    j
    g
    p
    • 4
    • 8
  • h

    herlevsen

    04/07/2020, 3:47 PM
    Is there anything like
    undefined
    from Haskell, in Kotlin? I can of course just cast any value to the type i need, but just typing
    any
    would be easier 🙂
    t
    • 2
    • 2
  • d

    dnowak

    04/08/2020, 8:58 AM
    Hi, I’m looking for some examples on how to use JDBC with Arrow. I want to run a bunch of IO effects in a single DB transaction. Is it doable?
    s
    • 2
    • 4
  • a

    Anton K

    04/08/2020, 6:57 PM
    Hello Arrow people! Following this presentation from Runar (

    https://youtu.be/hmX2s3pe_qk?t=1494▾

    ) I was trying to reimplement the code written in Scala from the presentation (Free Monad + BolAlg) in Kotlin with Arrow. Unfortunately I got stuck 😕 In particular I do not understand what should be the type of
    s
    parameter in
    Suspend
    ? You can find my implementation here: https://github.com/kuschanton/fp-in-kotlin/blob/master/src/main/kotlin/fp/kotlin/monad/free/Expr03.kt Any help appreciated 🙂 Kind regards, Arrow newbie
    p
    r
    • 3
    • 5
  • p

    pakoito

    04/09/2020, 1:05 PM
    I don't believe that's a use case we have..or even like to have
    • 1
    • 1
  • p

    pakoito

    04/09/2020, 1:05 PM
    what business logic requires it?
    d
    s
    s
    • 4
    • 33
  • s

    Satyam Agarwal

    04/09/2020, 2:29 PM
    Also when working with Reader, it was a bit hassle when 3-4 function that have Reader as return type. I was `ask`ing and `extract`ing many times. Ofcourse that because of my limited fp exp. Perhaps ReaderT could’ve simplified it, but I never got it working 😞
    r
    • 2
    • 8
  • p

    pakoito

    04/10/2020, 12:21 PM
    mechanically, if you’re going to ignore the error anyway you might as well say it was Throwable all along
    g
    • 2
    • 1
  • p

    pakoito

    04/10/2020, 12:23 PM
    semantically, 
    Either<Nothing, Either<Throwable, Int>>
     is correct
    so you
    fold({ exception }, { it.fold({ error }, { success })})
    g
    • 2
    • 21
  • j

    Jérémy CROS

    04/10/2020, 2:08 PM
    Hi guys. We’re replacing our custom made Optionnal with Arrow’s and I’m having a struggle chosing a syntax. What do you think? Both are the same? Or is there a prefered syntax? Or even a third option? (also, I have a few more like that 😄 hopefully, it has not already been answered a billion times 😄)
    Untitled
    r
    i
    • 3
    • 9
  • j

    Jakub Pi

    04/13/2020, 4:26 PM
    I'm working my way through the Red Book, trying to do some of the exercises in Kotlin. In chapter 9, there's an example that uses a type constructor (the book itself uses Scala).
    trait Parsers[ParseError, Parser[+_]] {	
      def run[A](p: Parser[A])(input: String): Either[ParseError,A]
    }
    I've tried to express this using Arrow as below:
    class ForParser private constructor()
    typealias ParserOf<T> = Kind<ForParser, T>
    inline fun <T> ParserOf<T>.fix(): Parser<T> = this as Parser<T>
    
    class Parser<A>(val v: A) : ParserOf<A>
    
    interface Parsers<ParseError> {
        fun <A> run(p : Parser<A>) : (String) -> Either<ParseError, A>
        fun char(c : Char) : Parser<Char>
    }
    So, this is my first pass which actually doesn't give any compile-time errors. But I'm confused by a few points: • Parsers interface is now only generic on the error and not on the Parser, what am I missing and how do I express it? • What is the syntax for the annotation
    @higherkind
    to eliminate the first three lines of boilerplate? If I just annotate the Parser class, ParserOf is flagged as undefined. • I'm not calling fix() anywhere, would I do that in the concrete implementation? • Scala seems to have a nice syntax for declaring curried functions and I've eliminated the named parameter input when I translated the run function. Is there a better way to express this? BTW Found this talk really helpful https://yowconference.com/talks/jacob-bass/yow-lambda-jam-2018/higher-kinded-types-in-a-lower-kinded-language-functional-programming-in-kotlin-code-jam-6368/
    👀 1
    m
    r
    • 3
    • 8
  • c

    CLOVIS

    04/13/2020, 7:16 PM
    Is there a document somewhere with a comprehensive list of future plans? I've heard about many depreciations, the Meta plugin removing the need to fix, etc. Is there a list somewhere to explain what major changes are to come?
    r
    g
    • 3
    • 13
  • p

    pakoito

    04/14/2020, 3:25 PM
    we already have it on arrow-syntax
    c
    r
    s
    • 4
    • 12
  • d

    dnowak

    04/14/2020, 10:03 PM
    Hi, Is the
    IO.unsafeRunSync()
    so dangerous that it cannot be called in production code? I need to execute
    IO
    in the current thread and
    unsafeRunSync
    seems reasonable in such case. Questions: 1. What can go wrong during the execution of
    unsafeRunSync
    ? 2. How to execute
    IO
    in the current thread?
    p
    • 2
    • 4
  • n

    Nicolas Lattuada

    04/15/2020, 9:23 AM
    Hi! What is the recommended way to do circuit breakers with arrow? I have a project with arrow core but I am not to eager to add resilience4j, because it brings vavr and it is going to be confusing to mix with arrow.
    s
    p
    • 3
    • 9
  • p

    pakoito

    04/15/2020, 9:41 AM
    if circuit breakers is what I think they are, flatMap with Option/Either/Validated should be enough
    n
    • 2
    • 2
  • r

    rcfgnu

    04/15/2020, 11:48 AM
    Hi, I'm new to arrow and already passionate, and try to use IO with Either to have a typed error but I'm stuck with the composition of dependent function like:
    fun x() : IO<Either<Failure,String>>
        fun y(xResult: String) : IO<Either<Failure,Int>>
        fun z(yResult: Int) : IO<Either<Failure,String>>
    It's my design totally wrong?
    i
    j
    • 3
    • 6
  • j

    Jorge Castillo

    04/15/2020, 11:56 AM
    It's fine for now, unless you want to type your errors as throwables and use IO<A>. In 0.11.0 IO<E, A> is coming, and you'll be able to drop the nested Either.
    👍 2
    😍 2
    r
    • 2
    • 1
  • p

    Phani Mahesh

    04/19/2020, 7:00 AM
    Can arrow be used without kapt? Just the monad implementations for option either etc?
    g
    r
    p
    • 4
    • 20
  • i

    Ivan Brko

    04/22/2020, 1:02 PM
    Hi, I'm new to Kotlin and I just started playing with Arrow and I can't understand something. This is an example from the documentation:
    fun magic(s: String): Either<Exception, String>
    
    val x = magic("2")
    val value = when(x) {
        is Either.Left -> when (x.a){
            is NumberFormatException -> "Not a number!"
            is IllegalArgumentException -> "Can't take reciprocal of 0!"
            else -> "Unknown error"
        }
        is Either.Right -> "Got reciprocal: ${x.b}"
    }
    And above the code, the following is written: You should also notice that we are using SmartCast for accessing 
    Left
     and 
    Right
     values. I expected that to mean that after matching X with Either.Left, the compiler would know that x is of type Exception (and the same for right, but there that x is of type String). Here you still have to call .a or .b to get the value. So sorry if this is a stupid question, but what exactly is smart casted here and would it be possible to get Kotlin to know that x is of type String after matching it with Right here?
    m
    t
    p
    • 4
    • 10
  • a

    antonicg

    04/22/2020, 4:00 PM
    Hey, anybody knows why the
    catch
    function from the
    Either
    is a suspend function? Is it possible to catch an exception without using an
    IO
    ?
    s
    p
    • 3
    • 5
  • i

    Ivan Brko

    04/22/2020, 6:59 PM
    What would be an idiomatic way to create Either if I am not assigning it to a variable so I can't specify its exact type. To be more precise, I am trying to convert a Result to Either. If Result is Ok want to give that value to right, if Results contain a Throwable I set left to sam error. Code is something like this:
    fun <T : Any> Result<T>.toEither(): Either<RequestError, T> =
        fold({ Either.right(it)}, {Either.left(calculateError())})
    However, this doesn't compile (although Intellij doesn't show that anything is wrong with the code), as
    Either.right
    creates
    Either<Nothing, T>
    and
    Either.left
    creates
    Either<T, Nothing>
    , so neither branching of the fold returns the needed type. Can I create wanted Either here (without having to create it with val, specify its exact type and returning that). I hoped simply doing something like
    Either<RequestError, T>.right
    would work, but of course it doesn't 😄
    r
    p
    • 3
    • 9
  • p

    pakoito

    04/24/2020, 3:46 PM
    handleErrorWith
    ?
    m
    • 2
    • 21
  • s

    Skotar

    04/24/2020, 8:27 PM
    Hello everyone! I use v0.11.0-SNAPSHOT and I encountered an issue (at least in my understanding):
    class OneError
    class TwoError
    
    private fun oneEither(): Either<OneError, String> = OneError().left()
    private fun twoEither(value: String): Either<TwoError, Int> = value.toInt().right()
    
    fun either() {
       oneEither()
         .flatMap { twoEither(it) }
         .fold(
           { throw Exception(it::class.simpleName) },
           { ... }
         )
    }
    
    private fun oneIO(): IO<OneError, String> = IO.raiseError(OneError())
    private fun twoIO(value: String): IO<TwoError, Int> = IO.just(value.toInt())
    
    fun io() {
       oneIO()
         .flatMap { twoIO(it) }
         .unsafeRunSyncEither()
         .fold(
           { throw Exception(it::class.simpleName) },
           { ... }
         )
    }
    The function
    either
    throws
    java.lang.Exception: OneError
    as I expect. But the function
    io
    throws
    OneError cannot be cast to class TwoError
    . When I look at the signature of
    flatMap
    (
    fun <E, A, B, E2 : E> IOOf<E, A>.flatMap(f: (A) -> IOOf<E2, B>): IO<E2, B>
    ), I think that it shouldn't even compile. Can you tell me if my understanding is correct? I expect that
    IO
    with two types should behave like
    Either
    .
    p
    r
    • 3
    • 5
  • d

    davec

    04/24/2020, 9:34 PM
    ---- (off topic from the previous question) --- Let's say I have a function like this:
    fun doSomething(name:String): Either<FailReason,Int>
    and I have a
    names:List<String>
    . I could do
    val result:List<Either<FailReason,Int>> = names.map { doSomething(it) }
    which is going to give me a list of
    Either
    instances. Fine. Now let's assume I want the iteration to stop upon the first case that
    doSomething()
    returns a left. This could be done using a sequence like this:
    val result2:Either<FailReason,Int> = names.asSequence().map { doSomething(it) }.first { it is Either.Left }
    but it's going to return the first left that fails, or the right that results from the last call to
    doSomething()
    . All intermediate "right" values will be discarded. What if I wanted it to return
    Either<FailReason,List<Int>>
    ? Essentially, return the first left (terminating any subsequent calls to
    doSomething()
    ), or a list of all the rights? Does Arrow provide any help here? (Also I'm not looking for a solution involving while loops or mutable variables.)
    p
    • 2
    • 14
Powered by Linen
Title
d

davec

04/24/2020, 9:34 PM
---- (off topic from the previous question) --- Let's say I have a function like this:
fun doSomething(name:String): Either<FailReason,Int>
and I have a
names:List<String>
. I could do
val result:List<Either<FailReason,Int>> = names.map { doSomething(it) }
which is going to give me a list of
Either
instances. Fine. Now let's assume I want the iteration to stop upon the first case that
doSomething()
returns a left. This could be done using a sequence like this:
val result2:Either<FailReason,Int> = names.asSequence().map { doSomething(it) }.first { it is Either.Left }
but it's going to return the first left that fails, or the right that results from the last call to
doSomething()
. All intermediate "right" values will be discarded. What if I wanted it to return
Either<FailReason,List<Int>>
? Essentially, return the first left (terminating any subsequent calls to
doSomething()
), or a list of all the rights? Does Arrow provide any help here? (Also I'm not looking for a solution involving while loops or mutable variables.)
Here's one possible solution:
fun <F,A,B> Sequence<F>.shortCircuitEither(fn: (F) -> Either<A,B>): Either<A,List<B>> {
        val items = mutableListOf<B>()
        this.forEach {item ->
            fn(item).fold(
                { return it.left() },
                { items.add(it) }
            )
        }
        return items.right()
    }
Usage:
val result =names.asSequence().shortCircuitEither { doSomething(it) }
Result will be Either a left value containing the first fail, or a List of all the right values.
p

pakoito

04/25/2020, 3:00 AM
what you’re looking for is called
sequence
, which is a specialised
traverse
names.traverse(Either.applicative()) { doSomething(it) }
that returns
Either<Error, List<Bla>>
if
doSomething
returns
Either<Error, Bla>
if you already have a
List<Either<Error, Bla>>
just call
sequence(Either.applicative())
d

davec

04/25/2020, 6:25 PM
ah thanks!
@pakoito follow on question...
traverse
doesn't actually return an
Either
, everything's wrapped in a
Kind
. Example:
val numbers = listOf(3,5,0,1,10)
fun fn(a:Int):Either<FailReason, Int> = if (a == 0) FailReason.left() else a.right()
val traverseResult:Kind<EitherPartialOf<FailReason>, Kind<ForListK, Int>> =
        numbers.traverse(Either.applicative(), ::fn)
So the problem is it's a Kind of an Either with the right of the Either as another Kind. In order to convert all that stuff back into a normal either I could do this:
val resultAsEither:Either<FailReason, List<Int>> = traverseResult.fix().flatMap{ it.fix().right() }
but is there a better way?
p

pakoito

04/28/2020, 11:34 PM
not at the moment, no
traverseResult.fix().map{ it.fix() }
that. It’s not better, just shorter.
👍 1
View count: 13