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

    Francis Reynders

    03/07/2023, 4:08 PM
    Hi, I try to apply the new Raise functionality to some new code. Does this look like a correct way to use it? Trying to instantiate HttpClient and WsHttpClient in a safe way using either, catch and Raise DSL. Any feedback is appreciated.
    s
    3 replies · 2 participants
  • n

    Norbi

    03/07/2023, 8:29 PM
    I've just run into an interesting problem related to
    raise()
    . The code in my next message references different
    catch()
    functions, and their return type and semantic is different as well. How should I refactor the second
    eagerEffect {}
    call to make it execute
    fold()
    in the background?
    s
    p
    +1
    45 replies · 4 participants
  • a

    Alejandro Serrano Mena

    03/08/2023, 2:55 PM
    Call for users and use cases for new Arrow website 🗣️ The Arrow team is currently working on a revamped website (to be announced soon), and as part of it we would like to show how our ecosystem is used in practical settings. If you are using Arrow and want to contribute to this new website, we would love to hear from you! Anything from a logo of your company as user to a description to how you use Arrow in particular is welcome. 🎙️ If you want to contribute but are not a fan of writing, I’m more than happy to sit down with you, have a friendly chat, and then write everything down. If you (and your employer) are happy with the result, we’ll then place it in our new Use cases section. 🙏 Thanks in advance for all your help!
    t
    1 reply · 2 participants
  • n

    Norbi

    03/10/2023, 9:57 AM
    What am I doing wrong with
    Raise<R>
    , how should I use it in "real" code? My problem is: 1. I've found that very often I want to know the root cause of an error - so I've reinvented the
    cause
    mechanism of exceptions 😐 2. I've found that by handling
    raise()
    -d errors, the contextual information is lost at the top level, where I maybe want to log a stack trace for easier investigation of the problem. Do you have some practical advice for using it? Maybe my head has just "stuck" thinking only by exceptions 🙂 Thanks.
    s
    s
    +1
    9 replies · 4 participants
  • m

    Marko Novakovic

    03/10/2023, 11:21 AM
    is there
    import arrow.core.memoize
    for
    suspend fun
    ?
    s
    y
    4 replies · 3 participants
  • m

    Marko Novakovic

    03/10/2023, 5:54 PM
    is there arrow ktor call adapter? like there used to be, or maybe there still is, Retrofit adapter or
    Either
        .catch { httpClient.get("") }
        .map { it.body() }
    is enough?
    j
    s
    3 replies · 3 participants
  • d

    dave08

    03/12/2023, 3:42 PM
    Funny, I thought that when using
    context(Raise<...>)
    requires
    suspend fun
    since all side-effects should be
    suspend fun
    ... am I wrong?
    c
    y
    +1
    7 replies · 4 participants
  • t

    Tower Guidev2

    03/13/2023, 9:32 AM
    Hi is it possible to employ
    arrow.retrofit.adapter.either.ResponseE
    in retrofit calls as follows:-
    @FormUrlEncoded
        @POST(OAUTH2_TOKENS_URL_PATH)
        suspend fun accessToken(
            @HeaderMap headers: Map<String, String> = emptyMap(),
            @FieldMap(encoded = true) fields: Map<String, String>
        ) : ResponseE<CallError, AccessTokenResponse>
    where
    CallError
    is
    arrow.retrofit.adapter.either.networkhandling.CallError
    as when i execute my android application I recieve a kotlin serialisation error stating no serialiser can be found for CallError do i have to supply my own custom version of CallError that is annotated as @Serializable? I am using this version of Arrow
    api platform('io.arrow-kt:arrow-stack:1.1.5')
    api 'io.arrow-kt:arrow-core'
    api 'io.arrow-kt:arrow-core-retrofit'
  • c

    CLOVIS

    03/13/2023, 10:36 AM
    It's confirmed that multi-platform context receivers won't be available before Kotlin 2.0.
    j
    s
    +2
    46 replies · 5 participants
  • d

    dave08

    03/13/2023, 4:27 PM
    If I have:
    fun foo() = effect {
      raise(DomainError)
    }
    
    fun bar() = effect {
      val context = ....
      val result = foo().bind()
    }
    
    data class WrappedError(val context: Context, val error: DomainError)
    
    // elsewhere
    bar().fold({ e -> // I need e to be WrappedError but I can only get the context in bar() ... and foo() raises DomainErrors w/o the context. }) { ... }
    s
    10 replies · 2 participants
  • d

    dave08

    03/13/2023, 4:28 PM
    Is there a way to somehow map the error for the fold?
  • d

    dave08

    03/13/2023, 4:58 PM
    I'm trying to seperate this into a function outside the
    effect { }
    block processing the request:
    val formParameters =
        catch({ call.receiveParameters() }) { e -> raise(GenericRequestFailure(e.message ?: "")) }
    but I can't since I don't have a Raise<> context (and I need the ApplicationCall as the receiver), do I just have to create another effect { } block for it and then use
    bind()
    or is there a better way? It seems like
    Either.catch...
    is deprecated... (and doesn't have a raise function?)
    p
    s
    12 replies · 3 participants
  • j

    Jorge Bo

    03/13/2023, 10:49 PM
    Hi, is it possible to do something like this on Arrow ?
    either {
        
    
       val changeType: String
    
        if (changeType == "do nothing") {
           //leave early, this is not an error
            return Either.Right("leave early)
        }
        ..do some complicated logic and leave
         "quit".right()
      }
    r
    s
    +1
    6 replies · 4 participants
  • m

    Marko Novakovic

    03/14/2023, 11:35 AM
    about piping. is piping, with dedicated operators etc., required only in languages that don’t support extension functions? for example: F#
    let f = [ 1; 2; 3; 4; 5 ] |> List.map (fun x -> x * 2) |> List.map string
    Kotlin
    fun f() = listOf(1, 2, 3, 4, 5).map { it * 2 }.map(Int::toString)
    it’s much nicer looking in Kotlin because
    map
    is en extension function. same goes for
    .let {}
    ,
    .apply {}
    etc.
    p
    4 replies · 2 participants
  • d

    dnowak

    03/14/2023, 1:26 PM
    A few questions about `Effects`: 1. Can I assume that they are what
    IO
    was in early versions of arrow? 2. Any advantage of using
    Effect
    compared to
    suspended function
    ? 3. Where can I find some “reference” code showing how to use effects - combining small effects into larger ones, using effects in the application?
    s
    6 replies · 2 participants
  • f

    Fred Friis

    03/14/2023, 1:45 PM
    What is the current take on Kotlin's native Result vs eg Arrow Either/Try? I've used Either/Try in my previous team, about to join a team that prefer using Result instead. They seem kinda similar to me (Result needs throwables as errors which is a bit different but whatever) but then there are people that claim that Kotlin devs themselves advocate against using Result in your business code as it will catch all exceptions, which isn't really desirable (see https://stackoverflow.com/questions/70847513/when-and-how-to-use-result-in-kotlin)
    s
    p
    +2
    45 replies · 5 participants
  • r

    rednifre

    03/14/2023, 6:02 PM
    Was there a plan to remove Validated in favor of Either, or did I just imagine this? Or replacing Try with Either? Something like that?
    s
    p
    8 replies · 3 participants
  • r

    rednifre

    03/14/2023, 6:31 PM
    What’s with either requiring suspend? What about either.eager? Does either just require suspend so that you can use suspend functions inside of it?
    s
    12 replies · 2 participants
  • e

    Emil Kantis

    03/14/2023, 10:42 PM
    Is there any better built-in options for achieving the same results as this? (Arrow 2.0, doing input validation in a function with type
    EitherNel<CreateInvoiceError, A>
    )
    listOfNotNull(
             if (dueDate <= invoiceDate) CreateInvoiceError.InvalidDueDate(invoiceDate, dueDate) else null,
             if (rows.isEmpty()) CreateInvoiceError.NoRows else null,
          ).toNonEmptyListOrNull()?.let { raise(it) }
    s
    d
    +1
    47 replies · 4 participants
  • r

    rednifre

    03/15/2023, 8:36 AM
    What’s the situation regarding multi platform? Does everything work well on iOS/Swift and the web/js/ts?
    s
    c
    3 replies · 3 participants
  • c

    CLOVIS

    03/15/2023, 10:45 AM
    Sorry if this is off-topic, but a lot of people here have played with context receivers. If I write
    interface A
    interface B
    
    context(A, B)
    fun foo() { … }
    can I call it like this?
    class Context : A, B
    
    with(Context()) {
        foo()
    }
    Said otherwise, can a single object satisfy multiple context receivers?
    p
    s
    +2
    16 replies · 5 participants
  • d

    dave08

    03/15/2023, 12:10 PM
    Is there a way to use Optics to work with KotlinX Serialization's JsonObject hierarchy? i'd like to pinpoint on certain parts of a big, very nested json and just modify it...
    s
    84 replies · 2 participants
  • d

    dave08

    03/15/2023, 12:14 PM
    ... it seems like it wouldn't be possible even with optics-reflect... they don't use data classes for those JsonXXX classes 😞
  • r

    Raehat Singh Nanda

    03/16/2023, 1:21 PM
    Trying add arrow-meta compiler plugin to my project but it just seems like nothing's working for me compileOnly "com.github.arrow-kt.arrow-meta:compiler-plugin:-SNAPSHOT" tried adding this didn't work tried every possible version tried looking at forums even chat gpt couldn't help How do I add arrow-meta to my build.gradle? I need real help here, please someone
  • f

    Francis Reynders

    03/16/2023, 5:03 PM
    Hello. I would like to maintain a Resource in an object with some lifecycle. Meaning the resource is acquired during instantiation of the object and should be released when done (an
    onExit
    method will be called). The
    Rescource.use
    and
    resourceScope
    functions only provide the resource in the lambda, however I would like to have the resource available between object initialization and
    onExit
    , so during the lifecycle of the object). Is there a standard way to do so? I was thinking of creating a CoroutineScope and lauching a coroutine in the
    init
    part, running resourceScope there and waiting for cancellation. The
    onExit
    method would cancel that scope. However that would mean the acquired resource would need to be defined as a
    lateinit var
    rather than val since the compiler does not allow initialization from within the coroutine. It also seems a bit convoluted.
    class Test() {
    
      val scope = CoroutineScope(EmptyCoroutineContext)
      lateinit var resource: String
    
      init {
        scope.launch {
          resourceScope {
            resource = install({"test"}, { _,_ -> Unit })
          }
          awaitCancellation()
        }
      }
    If there is a better way I would love to hear about it.
    s
    10 replies · 2 participants
  • t

    Tom Everton

    03/17/2023, 2:31 PM
    Hey folks, happy Friday! I’ve thrown together an exploratory project using Arrow 2.0 and Http4k after getting more into FP since finishing the ‘Function Programming in Kotlin’ book. If anyone could spare some time to have a quick look and provide any feedback on how I’m using Arrow whether that’s reasonable and any other places that I’m not utilising it but it could help that would be really appreciated (feel free to make a PR or just reply here). The project is a simple Http service with which you can create, get and solve simple quizzes. To use the quiz endpoints you need to register with the user endpoint and use those credentials as Basic Auth. There’s a lot of real-world input validation missing as this is just a test project. You can find it here: https://github.com/TevJ/kfp-quiz Thanks
    s
    d
    7 replies · 3 participants
  • d

    dave08

    03/19/2023, 11:53 AM
    Hi! It seems like if I have
    { "some": "json" }
    and I have
    JsonPath["some2"].set(json, JsonPrimitive("json2"))
    it just silently doesn't do anything... I would have expected it to create the new key. Is there any way to do that?
    s
    13 replies · 2 participants
  • d

    dave08

    03/19/2023, 12:42 PM
    Actually, maybe this is the behaviour of Optics? That an Optional's setter can't set what it didn't find?
    s
    1 reply · 2 participants
  • d

    dave08

    03/19/2023, 4:50 PM
    Funny... even with suspendApp ( with the resource library for Ktor) and I still get things like what I posted in the thread...
    s
    3 replies · 2 participants
  • a

    asdf asdf

    03/19/2023, 7:10 PM
    Is there any reason that arrows
    either
    builder has to be called from a suspending context? It seems to work fine with a non-suspending implementation like this:
    fun main() {
        val res = nonSuspendingEither {
            if (Random.nextBoolean()) shift(AuthResult.Success(534))
            else AuthResult.Failure("Invalid")
        }
        println(res)
    }
    
    @RestrictsSuspension
    interface RestrictedEffectScope<E> : EffectScope<E>
    
    fun <E, A> nonSuspendingEither(closure: suspend RestrictedEffectScope<E>.() -> A): Either<E, A> {
        var result: Either<E, A>? = null
        val scope = object : RestrictedEffectScope<E> {
            override suspend fun <B> shift(r: E): B {
                result = Either.Left(r)
                return suspendCoroutine { /*no-op*/ }
            }
        }
        closure.startCoroutine(scope, Continuation(EmptyCoroutineContext) {
            result = Either.Right(it.getOrThrow())
        })
        return result!!
    }
    s
    2 replies · 2 participants
Powered by Linen
Title
a

asdf asdf

03/19/2023, 7:10 PM
Is there any reason that arrows
either
builder has to be called from a suspending context? It seems to work fine with a non-suspending implementation like this:
fun main() {
    val res = nonSuspendingEither {
        if (Random.nextBoolean()) shift(AuthResult.Success(534))
        else AuthResult.Failure("Invalid")
    }
    println(res)
}

@RestrictsSuspension
interface RestrictedEffectScope<E> : EffectScope<E>

fun <E, A> nonSuspendingEither(closure: suspend RestrictedEffectScope<E>.() -> A): Either<E, A> {
    var result: Either<E, A>? = null
    val scope = object : RestrictedEffectScope<E> {
        override suspend fun <B> shift(r: E): B {
            result = Either.Left(r)
            return suspendCoroutine { /*no-op*/ }
        }
    }
    closure.startCoroutine(scope, Continuation(EmptyCoroutineContext) {
        result = Either.Right(it.getOrThrow())
    })
    return result!!
}
s

simon.vergauwen

03/19/2023, 7:35 PM
Hey @asdf asdf, This is an implementation detail in 1.1.x, and you can use
either.eager
to achieve the same as you do here with
@RestrictSuspension
. In fact the implementation is 99% the same. However in 1.2.x we've simplified this, and
either
is simply
inline fun
there. You can use it in
1.1.6-alpha.59
, it's source compatible with 1.1.x given some extra imports 😉
a

asdf asdf

03/19/2023, 7:58 PM
Neat, thanks!
View count: 2