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

    Quantum64

    04/30/2022, 5:39 PM
    Any update on this? https://github.com/arrow-kt/arrow/issues/2668 This is a pretty serious spec violation in my opinion. We don't want users to become dependent on this behavior.
    s
    • 2
    • 4
  • s

    Satyam Agarwal

    05/01/2022, 11:44 AM
    Hi, Another question. I have two lists, List<A>, and List<B>, and I want to pass them through Ior to perform actions based on if they are empty or not. Only sensible logic I’ve been able to get to so far, is,
    Ior.fromNullables(Nel.fromList(list1).getOrElse { null }, Nel.fromList(list2),getOrElse { null})
    This is obviously not good, as
    Nel<A>?
    effectively means
    List<A>
    , so i can just
    list1.isEmpty() && list2.isEmpty
    to cover
    Ior
    cases. However, what I want is
    Nel
    after checking the states. Is there something better that can be done here ? Pattern matching on
    Option<Nel<A>> to Option<Nel<B>>
    also doesn’t work. I can’t say for example
    when exp is Pair<Some, None>
    s
    m
    • 3
    • 10
  • r

    Robert Kittilsen

    05/03/2022, 12:29 AM
    Hi everyone! 👋 😄 I’ve just started to use Arrow and I’ve come across this situation where I’m not totally sure what I’m supposed to do or what is best practice. I have this function in a file service:
    fun getSignedUrl(fileName: String): Either<FileError, URL>
    in which I
    Either.catch
    a generation of a signed URL and
    mapLeft
    for a potential
    FileError.SignedUrlError
    . In another service I have a function that looks like this:
    fun getReports(): Either<GeneralError, List<Report>>
    . In this I’m mapping through each report and replacing filenames with a call to
    getSignedUrl
    . I want to do it eagerly and go left on first fail. In the end I’m folding into a HttpResponse like this:
    fun <BODY> Either<GeneralError, BODY>.toResponse(): HttpResponse<BODY>
    As you can see I have two different Error objects and nested Either’s. The only solution I’ve found without changing
    FileError.SignedUrlError
    into
    GeneralError
    is something like this:
    fun <OUTER_TYPE, INNER_TYPE, ERROR_TYPE> Collection<OUTER_TYPE>.mapEitherReturningFirstLeft(block: (item: OUTER_TYPE) -> Either<ERROR_TYPE, INNER_TYPE>): Either<ERROR_TYPE, List<INNER_TYPE>> =
        this.map { item ->
            block(item).fold(
                ifRight = { it },
                ifLeft = { return it.left() }
            )
        }.right()
    This doesn’t seem optimal. Any suggestions or thoughts will be much appreciated! 🤩
    s
    • 2
    • 3
  • j

    julian

    05/03/2022, 1:40 AM
    Hi, @simon.vergauwen. Thanks for your blog post on
    Effect
    . It all made sense to me, except for this:
    Only when
    fold
    is called it will create a
    Continuation
    and run the computation, this means
    Effect
    can encode
    side-effects
    as
    pure values
    .
    What does pure values mean? I know what a pure function is, but I don't think I've ever come across pure values.
    s
    s
    • 3
    • 5
  • g

    genovich

    05/04/2022, 4:34 PM
    Hello colleagues! I’ve just found that implementations of
    raceN()
    probably not handling exceptions in a right way. According to the conversation I had a year ago, it seems to me that if one of functions will throw an exception, then another will not be cancelled. Do you have an idea how to check such behaviour?
    s
    • 2
    • 13
  • j

    Jose Antonio Jimenez

    05/06/2022, 10:41 AM
    Currently i am having this error:
    > Failed to query the value of task ':kspKotlin' property 'options'.
       > Could not resolve all files for configuration ':kspKotlinProcessorClasspath'.
          > Could not find io.arrow-kt:arrow-optics-ksp-plugin:1.0.1.
            Required by:
                project :
    i
    • 2
    • 1
  • s

    Stylianos Gakis

    05/09/2022, 12:27 PM
    Hey people! We’ve been having a discussion regarding using Either and what should go on Left and what on Right with my team. There are some things that we feel are up to interpretation so we’d love to hear more from people inside this community. The discussion is currently taking place here and since our repository is public we have the perk of sharing it here with others directly 😅 For people who don’t want to follow the link, I’ll try and ask the question here, but the main question is be this for those who do. Do you usually treat your Either lefts as all the unknown things that could go wrong (Network error, some exception happening etc.) and the rights as the known results, whether that’s the “success” case, or if it’s a known “failed” result that you know can happen. Or do you put the known “failed” result on the left as well along with all the unknown errors, exceptions etc ? To try to explain with an example, let’s say that we have a function:
    fun getLoginResult(): Success|WrongPassword|NetworkError
    Would you map this to
    Either<NetworkError,Success|WrongPassword>
    or
    Either<NetworkError|WrongPassword,Success>
    ? I also understand that both can work, technically one could flip Right and Left too, but we’re trying to see what the “convention” is to try and conform to whatever feels more standard. Feel free to respond here or there, either works for us, but probably here so that other people can benefit in the future.
    s
    p
    +3
    • 6
    • 11
  • m

    Marko Novakovic

    05/09/2022, 12:33 PM
    how to use
    Flow
    and
    Either
    ? is having
    Flow<Either<A, B>>
    a good option? also, are there any plans for some monadic streaming Flow-like API?
    👍 1
    s
    • 2
    • 4
  • b

    bloder

    05/10/2022, 11:15 PM
    Hi all! Thank you for
    Effect
    feature, really cool how I can type all my effects and play with them purely, one doubt about it: Are we thinking in explore more about Algebraic Effects and bring its concept to this implementation?
    👋 1
    r
    s
    • 3
    • 4
  • o

    Oliver Eisenbarth

    05/14/2022, 4:36 PM
    Hi @simon.vergauwen. 👋 I get Either and Validated and I've learned, that Kotlin suspend is better than having IO wrappers. What's the benefit of
    effect
    ? Please explain it to me like I'm five. 🙂
    p
    b
    +3
    • 6
    • 13
  • a

    alightgoesout

    05/15/2022, 5:07 PM
    Is there a plan to add a a function on
    Effect
    like
    leftIfNull
    for
    Either
    ? Right now I do:
    effect {
        ensureNotNull(someEffect.bind()) { SomeError("…") }
    }
    which seems verbose
    s
    • 2
    • 5
  • p

    Pavel

    05/16/2022, 7:26 AM
    Hi, since we are all talking about
    Effect
    I would have one question too. Is it possible to compose multiple `Effect`s? For example:
    fun test(): Effect<X, Int> = effect {
        1
    }
    
    fun test2(num: Int): Effect<X, Int> = effect {
        num + 1
    }
    
    (test().flatMap { num -> test2(num) }): Effect<X, Int>
    s
    • 2
    • 4
  • t

    than_

    05/16/2022, 9:14 AM
    Hi, I'm playing with the effects and I found out that
    sealed interface DomainError
    object SomeDomainError: DomainError
    
    fun foo(): Effect<DomainError, Unit> = TODO()
    fun bar(): Effect<SomeDomainError, Unit> = TODO()
    
    fun baz() = effect<DomainError, Unit> {
        foo().bind()
        bar().bind()
    }
    the problem is I cannot bind result of
    bar
    even though
    SomeDomainError
    is a
    DomainError
    . Is this known limitation, oversight, or weirdness on my side 🙂 ?
    i
    s
    • 3
    • 4
  • j

    jianbing

    05/19/2022, 7:45 AM
    Dear Arrow Core Team Please kindly help: I am using arrow-core:1.0.1 in my kotlin project. recently I upgraded kotlin version from 1.6.0 to 1.6.21 and ktor from 1.6.0 to 2.0.1, but keep arrow-core version as it is now when I am building my kotlin project from remote CICD pipeline, I constantly observed the build failures (see the attachment for full stack). several re-tries can fix this problem. But I want to know the root cause here. I cannot search out any similar case from Bing.com for rootcause. hence I have no clue what is happening around. Maybe arrow-core:1.0.1 will NOT work with latest 1.6.21 kotlin... Caused by: java.lang.IllegalArgumentException: Missing extension point: org.jetbrains.kotlin.com.intellij.documentWriteAccessGuard in container org.jetbrains.kotlin.com.intellij.core.CoreApplicationEnvironment$1@3b88f6af at org.jetbrains.kotlin.com.intellij.openapi.extensions.impl.ExtensionsAreaImpl.getExtensionPoint(ExtensionsAreaImpl.java:273) at org.jetbrains.kotlin.com.intellij.openapi.extensions.BaseExtensionPointName.getPointImpl(BaseExtensionPointName.java:28) at org.jetbrains.kotlin.com.intellij.openapi.extensions.ExtensionPointName.getExtensions(ExtensionPointName.java:38) at org.jetbrains.kotlin.com.intellij.openapi.editor.impl.DocumentImpl.assertWriteAccess(DocumentImpl.java:700) at org.jetbrains.kotlin.com.intellij.openapi.editor.impl.DocumentImpl.replaceString(DocumentImpl.java:605) at org.jetbrains.kotlin.com.intellij.openapi.editor.impl.DocumentImpl.lambda$setText$2(DocumentImpl.java:1083) at org.jetbrains.kotlin.com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:211) at org.jetbrains.kotlin.com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:177) at org.jetbrains.kotlin.com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:167) at org.jetbrains.kotlin.com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:153) at org.jetbrains.kotlin.com.intellij.openapi.editor.impl.DocumentImpl.setText(DocumentImpl.java:1088) at arrow.meta.quotes.QuoteProcessorKt$changeSource$1$1.invoke(QuoteProcessor.kt:205) at arrow.meta.quotes.QuoteProcessorKt$changeSource$1$1.invoke(QuoteProcessor.kt:203) at arrow.meta.phases.analysis.MetaFileViewProvider.getDocument(MetaFileViewProvider.kt:17) at org.jetbrains.kotlin.com.intellij.psi.AbstractFileViewProvider$VirtualFileContent.getText(AbstractFileViewProvider.java:468)
    compiling failures.txt
    i
    • 2
    • 3
  • k

    Katarzyna

    05/19/2022, 1:08 PM
    Hi everyone, @marcinmoskala is currently working on book series Kotlin for developers. It will contain 3 books: 1. Kotlin Essentials 2. Functional Kotlin 3. Advanced Kotlin He thought of adding a special chapter to the Functional Kotlin concerning the Arrow Library. We are looking for someone who would write this chapter as a guest author. What do you think? Let me know, here or write to kasia@kt.academy to discuss all the details. Have a nice day 🌞
    a
    r
    • 3
    • 3
  • m

    Marko Novakovic

    05/20/2022, 3:01 PM
    I was away from Arrow for some time and two days ago I came across
    Effect
    . can somebody give me concrete example where difference between
    Effect
    and
    Either
    is clear?
    s
    r
    • 3
    • 8
  • ł

    Łukasz Gendek

    05/23/2022, 7:33 AM
    Hi. Do you know why divide1 does compile and divide2 does not?
    s
    • 2
    • 13
  • s

    Satyam Agarwal

    05/24/2022, 5:02 AM
    Hei ! I was wondering what is the state of https://github.com/arrow-kt/arrow-endpoint ? Is this ready to be used ? (I haven’t browsed through the code) Looks like last tag is 0.1.1-alpha.5 from 2 days ago.
    s
    • 2
    • 2
  • j

    jean

    05/25/2022, 8:25 AM
    I have the following functions :
    fun interface PatchDevice<T> {
        suspend operator fun invoke(
            deviceId: String,
            payload: T
        ): Either<Error, Action>
    }
    
    fun interface PatchDeviceAttribute<T> {
        suspend operator fun invoke(
            deviceId: String,
            payload: T
        ): Either<Error, Action>
    }
    
    suspend fun <T> save(
        patchDevice: PatchDevice<T>,
        patchDeviceAttribute: PatchDeviceAttribute<T>
    ) {
        either.eager<> { 
            val patchDeviceResult = patchDevice("")
        }
    }
    The IDE complains that
    Restricted suspending functions can only invoke member or extension suspending functions on their restricted coroutine scope
    when I call
    patchDevice()
    What should I change to make it work?
    r
    • 2
    • 3
  • k

    kyleg

    05/25/2022, 2:59 PM
    Howdy do, it's been a couple years since I've been here. Arrow has gone through so much since then (Arrow Meta wasn't even out yet, and
    IO<A>
    hadn't been deprecated for suspend yet!). Quick question: didn't Arrow used to have a Free/FreeMonad implementation? I can't seem to find it in the codebase or the docs now. I found a gist for creating a DSL using Arrow (written three years ago) but I can't even find annotations like
    @higherkind
    to import them. It looks like there used to be a module arrow-free or something based on links in the gist, but I can't find that now.
    s
    • 2
    • 7
  • s

    Satyam Agarwal

    05/27/2022, 9:05 AM
    Hei Hei !! I recently bumped to arrow 1.1.2. And I was wondering the rationale behind deprecating ResultEffect. I’ve been using it in my tests a lot. ResultEffect.bind() helps a lot in providing prerequisites my tests need to assert on something. For example inserting rows in databases. Most of my operations are effectful, so I have to wrap them either in either or eagerEffect. With ResultEffect I didn’t need to use these computation blocks. Take a look at this simple test example :
    import arrow.core.computations.ResultEffect.bind
    
    @Test
    fun `encrypt produces new encryption for given text and should be decrypted back `() {
        val text = "Some sensitive data :partying_face: 2020-06-27T19:11:44.095Z @#$%^&*(&^%$#@! åååå πø˜˜¶∞¢"
        val textByteArray: ByteArray = text.toByteArray()
    
        val firstEncryption: ByteArray = Crypto.encrypt(securityKey, textByteArray).bind()
        val secondEncryption: ByteArray = Crypto.encrypt(securityKey, textByteArray).bind()
    
        firstEncryption shouldNotBe secondEncryption
    
        val firstDecryption: ByteArray = Crypto.decrypt(securityKey, firstEncryption).bind()
        val secondDecryption: ByteArray = Crypto.decrypt(securityKey, secondEncryption).bind()
    
        firstDecryption shouldBe textByteArray
        secondDecryption shouldBe textByteArray
        String(firstDecryption) shouldBe text
        String(secondDecryption) shouldBe text
    }
    Is there some alternative, or am I forced to migrate my hundreds of tests 😅
    s
    • 2
    • 11
  • m

    Marko Novakovic

    05/30/2022, 11:47 AM
    help needed I have top level function:
    suspend fun createTask(
        tasksDao: TasksDao,
        localDate: LocalDate,
        label: String,
    ): Either<TaskError, Unit> = either {
        ensure(label.isNotBlank()) { TaskError.EmptyLabel }
        try {
            tasksDao.createTask(localDate.year, localDate.monthNumber, localDate.dayOfMonth, label)
        } catch (e: Throwable) {
            shift(TaskError.CreationError)
        }
    }
    but it fails to compile for iOS target,
    Task :shared:linkDebugTestIosSimulatorArm64 FAILED
    happens on 1.1.2 and 1.1.3-alpha.14 works for Android error in thread
    s
    r
    • 3
    • 29
  • s

    stojan

    05/31/2022, 1:26 PM
    https://twitter.com/trupill/status/1531621986207678464
    👏🏼 1
    👏 4
    t
    • 2
    • 1
  • s

    simon.vergauwen

    05/31/2022, 2:32 PM
    message has been deleted
    🙌 2
    ❤️ 7
    g
    y
    +2
    • 5
    • 10
  • m

    Moritz Lindner

    06/01/2022, 8:29 PM
    Hi I have a question regarding combining 2 Monads. I have the following type
    Either<A, Option<B>
    and want to create a
    Either<A, B>
    . If the Option is
    None
    the Either should be
    Left<A>
    and if it is
    Some
    I want the Either to be
    Right<B>
    . I did not find a function in the library and since MonadeTransformers are not an option I came up with the following solution:
    fun <A, B> Either<A, Option<B>>.unwrapOptionOrElse(other: () -> A): Either<A, B> {
        return flatMap { option -> option.fold({ other().left() }, { it.right() }) }
    }
    Is this a reasonable way of handling this case or should I change something? Regards Moritz 🙂
    r
    i
    • 3
    • 16
  • j

    jean

    06/02/2022, 7:34 PM
    I’m trying to add arrow as a dependency on an older multiplatform project but I’m running in this issue
    Error while evaluating property 'filteredArgumentsMap' of task ':compileKotlinMetadata'
       > Could not resolve all files for configuration ':metadataCompileClasspath'.
          > Could not resolve io.arrow-kt:arrow-core:1.1.2.
            Required by:
                project :
             > The consumer was configured to find a usage of 'kotlin-api' of a library, preferably optimized for non-jvm, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'common'. However we cannot choose between the following variants of io.arrow-kt:arrow-core:1.1.2:
                 - iosArm32ApiElements-published
                 - iosArm64ApiElements-published
                 - iosSimulatorArm64ApiElements-published
                 - iosX64ApiElements-published
                 - jsApiElements-published
                 - jvmApiElements-published
                 - jvmRuntimeElements-published
                 - linuxX64ApiElements-published
                 - macosArm64ApiElements-published
                 - macosX64ApiElements-published
                 - mingwX64ApiElements-published
                 - tvosArm64ApiElements-published
                 - tvosSimulatorArm64ApiElements-published
                 - tvosX64ApiElements-published
                 - watchosArm32ApiElements-published
                 - watchosArm64ApiElements-published
                 - watchosSimulatorArm64ApiElements-published
                 - watchosX64ApiElements-published
                 - watchosX86ApiElements-published
    this is my commonMain
    val commonMain by getting {
        dependencies {
            implementation("io.arrow-kt:arrow-core:1.1.2")
            implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.1-native-mt")
        }
    }
    Am I missing something here? I tried to add other multiplatform dependencies like ktor, and it did not have the same issue, it compiled just fine
    s
    • 2
    • 6
  • d

    Daniel Wojda

    06/06/2022, 9:35 AM
    👋 Hello, team! I'm trying to format my code according to Contributing guide (https://github.com/arrow-kt/arrow/blob/main/CONTRIBUTING.md#requirements-to-change-an-existing-feature)
    ./gradlew spotlessApply
    Unfortunately, the task fails with following error:
    FAILURE: Build failed with an exception.
    
    * What went wrong:
    Task 'spotlessApply' not found in root project 'arrow'.
    Did I miss some configuration step?
    s
    j
    i
    • 4
    • 6
  • l

    Luke

    06/14/2022, 9:11 PM
    Is there a function that takes a lambda with one parameter (
    (T) -> R
    ) and another parameter of type
    T
    and returns a lambda with no parameter (
    () -> R
    ) which when called runs the parameter lambda (
    (T) -> R
    ) with the instance of
    T
    ?
    y
    • 2
    • 1
  • t

    tavish pegram

    06/17/2022, 5:37 PM
    Hey y'all! I'm just starting to learn some reactive patterns and was wondering what people see the relationship between something like arrow or arrow fx and flux/mono/etc might be (and suspend)? Would you pick one over the other, or are they complementary or isomorphic?
    r
    d
    • 3
    • 5
  • p

    Partho Paul

    06/22/2022, 11:16 AM
    Hi all, I’m new to arrows. My use case is if an exception occurs in a function, then I want to catch it and do some post processing, something like this:
    fun f1(): Either<Throwable, String> {
    	either {
    		doSomething() //throws exception
    	}
    }
    
    fun f2() {
    	f1().fold(
    		{
    			print("you messed up")
                doErrorHandling()
    		},
    		{
    			print("everything's fine")
    		}
    	)
    }
    
    fun main() {
    	runCatching{
    		f2()
    	}
    	.onSuccess {
    		print("it worked")
    	}
    	.onFailure {
    		print("Either didn't catch exception")
    	}
    }
    When function f1() throws exception here, the code should print “you messed up” but instead it’s printing “Either didn’t catch exception”. Am I doing anything wrong here? I’m using kotlin 1.7.0 and arrow version 1.1.2 TIA
    s
    a
    r
    • 4
    • 12
Powered by Linen
Title
p

Partho Paul

06/22/2022, 11:16 AM
Hi all, I’m new to arrows. My use case is if an exception occurs in a function, then I want to catch it and do some post processing, something like this:
fun f1(): Either<Throwable, String> {
	either {
		doSomething() //throws exception
	}
}

fun f2() {
	f1().fold(
		{
			print("you messed up")
            doErrorHandling()
		},
		{
			print("everything's fine")
		}
	)
}

fun main() {
	runCatching{
		f2()
	}
	.onSuccess {
		print("it worked")
	}
	.onFailure {
		print("Either didn't catch exception")
	}
}
When function f1() throws exception here, the code should print “you messed up” but instead it’s printing “Either didn’t catch exception”. Am I doing anything wrong here? I’m using kotlin 1.7.0 and arrow version 1.1.2 TIA
s

stojan

06/22/2022, 11:28 AM
for code that throws you can use
Either.catch {}
or similar functions e.g.
Either.catch { doSomething() }
p

Partho Paul

06/22/2022, 11:29 AM
@stojan had tried it as well, but it wasn’t working as I intended to. Output was same as the either block
a

Alejandro Serrano Mena

06/22/2022, 11:41 AM
@Partho Paul what did you try exactly? I often find the combination of
Either.catch
within an
either
block a bit confusing
you either remove the block altogether
fun f1(): Either<Throwable, String> =
	Either.catch { doSomething() }
or you need to call
bind
to make the block aware of the thing being run
fun f1(): Either<Throwable, String> {
	either {
		Either.catch { doSomething() }.bind()
	}
}
p

Partho Paul

06/22/2022, 11:43 AM
@Alejandro Serrano Mena I had tried the below approach with Either.catch:
fun f1(): Either<Throwable, String> {
	Either.catch {
		doSomething() //throws exception
	}
}

fun f2() {
	f1().fold(
		{
			print("you messed up")
            doErrorHandling()
		},
		{
			print("everything's fine")
		}
	)
}

fun main() {
	runCatching{
		f2()
	}
	.onSuccess {
		print("it worked")
	}
	.onFailure {
		print("Either didn't catch exception")
	}
}
a

Alejandro Serrano Mena

06/22/2022, 11:44 AM
note that above you are "throwing away" the either, you need to define it as
fun f1(): Either<Throwable, String> =
	Either.catch { doSomething() }
(note that I'm using
=
and not braces)
☝️ 3
p

Partho Paul

06/22/2022, 12:37 PM
@Alejandro Serrano Mena Tried using
fun f1(): Either<Throwable, String> =
	Either.catch { doSomething() }
but still not able to catch exception in f2
s

stojan

06/22/2022, 12:40 PM
Either.catch
is basically a `try/catch`https://github.com/arrow-kt/arrow/blob/051847de3b1d3186fc9843864aaf642a2f4a854f/ar[…]libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Either.kt except if your exception is fatal e.g.: https://github.com/arrow-kt/arrow/blob/0afdd9a7cc5251cf0c50701b21ccbb5693045bde/arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/NonFatal.kt#L10
p

Partho Paul

06/22/2022, 12:55 PM
@stojan Thanks, this helps. The Exception I was getting from f1 was LinkageError which is fatal. Tested the code with other non fatal exceptions as per @Alejandro Serrano Mena’s suggestion and it was working.
r

raulraja

06/22/2022, 2:51 PM
@Partho Paul I’m curious about the use case to capture a fatal ex. like in this case
LinkageError
, how did you plan to recover from it? and what leads you to this point where you care about it in user code?
p

Partho Paul

06/22/2022, 3:39 PM
@raulraja So for me, f1() was a db call. In my use case, I’m trying to fetch a document from db and do some action based on the data received. If I don’t receive any data or the db call fails because of any exception, then I’ll perform another set of actions. I wasn’t aware that the sdk which I’m using inside f1() will return fatal exception as the error message was misleading. Currently I don’t have anything planned for recovering from this
LinkageError
. I’m migrating a legacy codebase into a new microservice. I’ll discuss it with my colleagues if we should continue the earlier workflow or short-circuit the process. I’ll be in favour of short-circuiting as continuing the earlier workflow will make the system less reliable.
👍 2
r

raulraja

06/22/2022, 4:53 PM
The reason I was asking is because
LinkageError
is fatal and usually means you are missing a native library file in the path and your application should not even be running at that point. Exceptions would be some kind of local application where the user is responsible to provide the linked libraries manually but that is an odd case. Normally you can’t recover from fatal exceptions because at that point for many of them you don’t even have guarantees the VM is in a recoverable state, for example
OutOfMemoryError
👍 2
View count: 19