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

    jrgonzalez

    08/01/2022, 8:50 AM
    Hi!. In this video (at the playback point on the link) an alternative way to model domain errors with extension functions and not requiring sealed / shared inheritance was hinted:

    https://www.youtube.com/watch?v=g79A6HmbW5M&t=1786s▾

    Is that on any code example / talk done afterwards already? I’m experimenting with things there, but would like to know the approach suggested on the talk cause it may be better / different and it would be nice to see before choosing something.
    s
    a
    • 3
    • 7
  • d

    dimsuz

    08/01/2022, 3:27 PM
    If I have
    val lens1: Lens<S, A>
    val lens2: Lens<S, B>
    how do I apply them one after another to change field
    A
    then change field
    B
    and return
    S
    ?
    fun modify(s: S): S {
      return lens1.modify { a.doStuff() } ?? lens2.modify { b.doStuff() }
    }
    i.e. I want not to compose them but to sequence them.
    s
    • 2
    • 3
  • s

    stojan

    08/03/2022, 1:28 PM
    My talk from Droidcon Berlin where I talk about Either and Validated (Form Validation on Android) https://www.droidcon.com/2022/08/02/error-handling-beyond-the-standard-library/
  • t

    Tower Guidev2

    08/03/2022, 2:25 PM
    Hi where am i going wrong? 🤦‍♂️
    s
    • 2
    • 8
  • l

    Lukasz Kalnik

    08/03/2022, 3:20 PM
    What is the advantage of using
    either
    over
    either.eager
    for suspending computations? If I use
    either.eager
    , will it simply block the current thread?
    suspend fun doSomethingLong(): Either<Error, Unit>
    
    either.eager {
        doSomethingLong() // does it block the current thread?
    }
    s
    s
    • 3
    • 21
  • t

    Tower Guidev2

    08/05/2022, 7:00 AM
    Hi I need some guidance on how to employ
    Either
    while completing related operations for example i am calling
    retrofit
    api calls then persisting the data into my local
    sqlite
    database i am employing
    io.arrow-kt:arrow-core-retrofit
    for my
    retrofit
    calls as follows:-
    /**
    * <https://api.discogs.com/artists/45467>
    *
    */
    @GET("artists/{artist_id}")
    suspend fun artist(@Header(HEADER_AUTHORISATION) accessToken: String = ACCESS_TOKEN, @Path("artist_id") artistId: Long): Either<CallError, ArtistResponse>
    then in my worker:-
    override suspend fun doActualWork(): Result {
    return repository
    .artist(artistId = 45467)
    .fold(
    ifLeft = { callError -> consumeCallError(callError) },
    ifRight = {
    val artist = ARTIST_MAPPER.map(it)
    println(artist)
    repository.database.artistDao().insertAsync(artist)
    Result.success()
    })
    }
    how can "wrap" or employ Either for the code i execute in my ifRight block above? e.g. the database insert. As I am using Room and it does not accept Either type
    s
    • 2
    • 9
  • r

    rednifre

    08/07/2022, 9:35 AM
    Why are the monad comprehensions like
    option
    or
    either
    suspend functions? Wouldn’t they work just as well without suspend?
    s
    f
    • 3
    • 3
  • y

    Yannick Lazzari

    08/08/2022, 3:04 PM
    🧵 Hi all. Looking for some advice/review on this small
    effect
    inspired builder/DSL that I created to wrap calls to gRPC services. Details inside the thread.
    s
    • 2
    • 10
  • j

    janvladimirmostert

    08/08/2022, 9:18 PM
    is there something in Arrow that would allow me to define a
    doSomething<T1, Tn, ..., Tn>(...)
    that would output
    On
    In other words, if I provide 5 generics, I want an
    O5<T1, T2, T3, T4, T5>
    as output and if I define 1 generic, I want
    O1<T1>
    as output
    g
    y
    p
    • 4
    • 59
  • d

    darkmoon_uk

    08/09/2022, 2:34 AM
    I just tried integrating Arrow Analysis for the first time in our project. The compiler fails on:
    Type alias SomeAlias should have a descriptor
    ...where
    SomeAlias
    is any Kotlin typealias that has a generic parameter (of several that we have in our project). Is Arrow known to not support generic type-aliases? Is there an annotation to suppress analysis for such types?
    a
    • 2
    • 1
  • e

    Emil Kantis

    08/10/2022, 10:02 PM
    Hey.. Is there any good pattern for this use case? I have an API that returns an
    Employee
    for instance.. I want it to have non-null values for a lot of fields which actually are nullable in the underlying system. So I would like to have my client deserialize the API response into a
    User
    and then use a
    toEmployee
    method that returns a
    ValidatedNel<Problem, Employee>
    .. More in thread.
    s
    s
    • 3
    • 12
  • y

    Yannick Lazzari

    08/12/2022, 12:25 AM
    Speaking of validations, here's a small editorial and suggested changes to the Error Handling Tutorial to promote what I would consider a slightly better practice with regards to which return type to use for validation functions (
    Validated
    vs.
    ValidatedNel
    ). The tutorial and most (or even all) examples I've seen on using the
    Validated
    type declare all validation functions using
    ValidatedNel
    type, even if the function only really ever returns a single error. For instance, a string field validation function that checks the length will either return a (single) length validation error, or the valid string, but the error is wrapped in the
    Nel
    . And the only reason I can think of is because when zipping the validated types together, one can simply do
    val someEntity: Validated<DomainError, SomeEntity> = 
      validateField1()
        .zip(SemiGroup.nonEmptyList(), 
             validateField2(), 
             validateField3()) { (v1, v2, v3) -> SomeEntity(v1, v2, v3) }
    i.e. not worry about dealing with
    Validated
    vs.
    ValidatedNel
    . I personally think the semantics are not accurate for these validation functions as we're false advertising that there could be multiple errors returned by each validation function. I think we should use the
    Nel
    type when the function can truly return multiple errors, otherwise you should stick with
    Validated
    . When zipping all your validated types together, it's really trivial to "sprinkle" a little
    toValidatedNel
    here and there to then accumulate all the errors together:
    val someEntity: Validated<DomainError, SomeEntity> = 
      validateField1SingleError().toValidatedNel()
        .zip(SemiGroup.nonEmptyList(), 
             validateField2MultipleErrors(), 
             validateField3SingleError().toValidatedNel()) { (v1, v2, v3) -> SomeEntity(v1, v2, v3) }
    Really nitpicking here, but I'm just curious to get other people's thoughts. Thanks!
    s
    • 2
    • 5
  • y

    Yannick Lazzari

    08/12/2022, 12:55 AM
    Second small comment regarding the Monad Comprehensions tutorial. We may want to update the examples as I noticed it uses the now deprecated
    arrow.core.computations.either
    object as opposed to its replacement
    arrow.core.continuations.either
    .
    s
    • 2
    • 2
  • y

    Yannick Lazzari

    08/12/2022, 12:57 AM
    And last question on validation: are there plans to introduce comprehensions for the
    Validated
    datatype? Or is it not possible? I think it would make composing validation functions easier.
    s
    • 2
    • 3
  • y

    Yannick Lazzari

    08/12/2022, 12:57 AM
    Apologies if the last 2 comments are already known issues/suggestions. Thanks!
  • l

    Lukáš Kúšik

    08/12/2022, 9:46 AM
    Hi! I am trying to model the error handling in our Android client. I have been inspired by this video

    (1) Building applications with Kotlin and Arrow.kt in style - YouTube▾

    , although I would like to apply these principles to the client side in this case. Let's say that there's a
    Repository
    which uses a
    RemoteApi
    and I'd like to create a new user on the backend. The
    RemoteApi
    does the POST call using Ktor, and returns the result of the
    Either<ApiError, UserDTO>
    type, where
    ApiError
    encapsules any network exceptions, internal server errors, etc. Now, I would like to parse expected errors (like
    UserAlreadyExists
    ) as
    UserError
    of the common
    DomainError
    sealed type (similar to the video). I'd like the
    Repository
    to get the`Either<ApiError, UserDTO>` from the
    RemoteApi
    , process the known errors and return something like the
    Either<UserError, UserDTO>
    type. The problem with
    Either<UserError, UserDTO>
    is, that
  • l

    Lukáš Kúšik

    08/12/2022, 10:17 AM
    Hi! I am trying to model the error handling in our Android client. I have been inspired by this video

    (1) Building applications with Kotlin and Arrow.kt in style - YouTube▾

    , although I would like to apply these principles to the client side in this case. Let's say that there's a
    Repository
    which uses a
    RemoteApi
    and I'd like to create a new user on the backend. The
    RemoteApi
    does the POST call using Ktor, and returns the result of the
    Either<ApiError, UserDTO>
    type, where
    ApiError
    encapsules any network exceptions, internal server errors, etc. Now, I would like to parse expected errors (like
    UserAlreadyExists
    ) as
    UserError
    of the common
    DomainError
    sealed type (similar to the video). I'd like the
    Repository
    to get the`Either<ApiError, UserDTO>` from the
    RemoteApi
    , process the known errors and return something like the
    Either<UserError, UserDTO>
    type. The problem with
    Either<UserError, UserDTO>
    is, that when a network exception occurs, it is an
    ApiError
    and not a
    UserError
    . The
    Repository
    would have to return something like
    Either<Either<ApiError,UserError>, UserDTO>
    which looks weird, or? So with a hierarchy like this:
    sealed interface Error
  • l

    Lukáš Kúšik

    08/12/2022, 10:31 AM
    Hi! I am trying to model the error handling in our Android client. I have been inspired by this video

    (1) Building applications with Kotlin and Arrow.kt in style - YouTube▾

    , although I would like to apply these principles to the client side in this case. Considering this hierarchy:
    sealed interface Error
    sealed interface ApiError : Error {
        object NetworkError : ApiError
        object Unauthorized : ApiError
        object ServerError : ApiError
    }
    sealed interface DomainError : Error
    sealed interface UserError : DomainError {
        object AlreadyExists : UserError
    }
    sealed interface BookError : DomainError {
        object AlreadyReserved : UserError
    }
    
    class RemoteApi {
        fun createUser(): Either<ApiError, UserDTO>
    }
    class Repository {
        fun createUser(): Either<UserError, UserDTO> (?) {
            val response: Either<ApiError, UserDTO> = remoteApi.createUser()
            // ... map known errors to UserError and return
        }
    }
    Let's say that there's a
    Repository
    which uses a
    RemoteApi
    and I'd like to create a new user on the backend. The
    RemoteApi
    does the POST call using Ktor, and returns the result of the
    Either<ApiError, UserDTO>
    type, where
    ApiError
    encapsules any network exceptions, internal server errors, etc. Now, I would like to parse expected errors (like
    UserAlreadyExists
    ) as
    UserError
    of the common
    DomainError
    sealed type (similar to the video). I'd like the
    Repository
    to get the`Either<ApiError, UserDTO>` from the
    RemoteApi
    , process the known errors and return something like the
    Either<UserError, UserDTO>
    type. The problem with
    Either<UserError, UserDTO>
    is, that when a network exception occurs, it is an
    ApiError
    and not a
    UserError
    . The
    Repository
    would have to return something like
    Either<Either<ApiError, UserError>, UserDTO>
    which looks weird, or? You could return
    Either<Error, UserDTO>
    to contain both
    ApiError
    and
    UserError
    , but then you would also allow the
    Error
    to be a
    BookError
    , which would get ugly in when statements. Maybe using
    Either<Error<UserError>, UserDTO>
    would be the best, but I'm having trouble modelling the data types like that. Does anyone know of an elegant solutions for this, or this problem of modelling errors in repositories overall? Thank you.
    s
    s
    o
    • 4
    • 11
  • t

    tavish pegram

    08/16/2022, 8:35 PM
    hello! I’ve been out of the loop for a bit but have been using arrow a lot at work which has been great. One think that has come up recently is the possibility of reducing boilerplate / mapping with explicit sealed classes for failures between layers/function calls with a kotlin Union type. I remember there being a POC for a union type a while ago. Is that something that’s close to being a reality? 🤞 So instead of
    sealed interface FooFailure {
      object Failure1: FooFailure
      object Failure2: FooFailure
    }
    fun foo(): Either<FooFailure, Unit> = TODO()
    
    sealed interface BarFailure {
      data class FooFailed(message: String): BarFailure
      object Failure1: BarFailure
      ...
    }
    fun bar(input: Input): Either<BarFailure, Unit> = either {
      input.validate().bind() // Could be BarFailure.Failure1
      foo().mapLeft { when (it) {
        FooFailure.Failure1 -> BarFailure.FooFailed("Failure 1")
        FooFailure.Failure2 -> BarFailure.FooFailed("Failure 2")
      }}.bind()
    }
    maybe
    sealed interface FooFailure {
      object Failure1: FooFailure
      object Failure2: FooFailure
    }
    fun foo(): Either<FooFailure, Unit> = TODO()
    
    sealed interface BarFailure {
      object Failure1: BarFailure
      ...
    }
    fun bar(input: Input): Either<BarFailure|FooFailure, Unit> = either {
      input.validate().bind() // Could be BarFailure.Failure1 or some other bar specific failure
      foo().bind()
    }
    but still being able to exhaustively when/pattern match on it. Ideally, in a flat way, but even having it be nested is fine.
    bar(someInput()).fold(
      ifLeft = { when (it) {
        FooFailure.Failure1 -> TODO()
        FooFailure.Failure2 -> TODO()
        BarFailure.Failure1 -> TODO()
      }}, 
      ifRight = { TODO() }
    )
    Thanks!
    s
    • 2
    • 7
  • e

    Emil Kantis

    08/17/2022, 8:32 PM
    I want to do
    String? -> Validated<E, String> -> Validated<E, A>
    (in my case converting a String? to UInt). First step is easy with
    fromNullable
    , but I'm not sure how to map a validated while catching.. I think I'm looking for a
    mapCatching(handleError: (Throwable) -> E, f: (A) -> B)
    but it doesn't seem to exist? 🙂
    s
    • 2
    • 3
  • d

    Dirk

    08/18/2022, 3:36 PM
    I wonder if there should be a variant in the EffectScope besides the existing suspend fun ensure(condition: Boolean, shift: () -> R): Unit, that expects a suspend () -> R function for shift. Would this be possible? If not, what would be an elegant alternative to this?
    s
    • 2
    • 3
  • s

    Stylianos Gakis

    08/19/2022, 2:27 PM
    [Fixed]
    ensureNotNull
    exists as an extension function on
    EffectScope
    Hm I tried to use the ensure function
    public suspend fun ensure(condition: Boolean, shift: () -> R)
    inside the
    EffectScope
    scope today and I was missing the nice functionality of the kotlin
    require
    function which by using a contract allows the compiler to auto-infer the type after that function. Specifically when doing a require not null check in my case. Since the ensure function does not do that, is there some other API I’m missing which could help me out, or should I just do
    !!
    since I know myself at that point that the item is not null?
    s
    y
    • 3
    • 10
  • r

    rcd27

    08/19/2022, 6:21 PM
    However, seems legit, but maybe there is an existing tool for such kind of tasks.
    l
    s
    • 3
    • 10
  • m

    Masrur Mirboboev

    08/22/2022, 6:51 AM
    Hello world, Recently I was playing around and trying to integrate
    arrow-optics
    into one of our projects, but stumbled upon an issue. When declaring a
    typealias
    in the same file where I have
    @optics
    annotation, build of the gradle application fails with
    Duplicated JVM name error
    . I was able to overcome the issue by declaring
    @file:JvmName("JvmNameOfFile")
    , but quite curious to know if there are any other more elegant ways to fix it and fix the root cause. Any help would be much appreciated 🙏
    s
    • 2
    • 2
  • s

    sam

    08/22/2022, 8:50 AM
    I thought you folks might be interested in my parse don't validate library that is built on Arrow's Validated and NonEmptyList types. https://github.com/sksamuel/tribune
    r
    • 2
    • 1
  • r

    raulraja

    08/22/2022, 12:17 PM
    Hello everyone! We are considering renaming the interface
    EffectScope
    and the operation
    shift
    to something else. 99% of the time shift is used for error propagation or short-circuiting. We were wondering which one of the following you prefer: 1️⃣ Shift
    context(Shift<Error>)
    suspend fun example(): Int = shift(Error)
    2️⃣ Raise
    context(Raise<Error>)
    suspend fun example(): Int = raise(Error)
    3️⃣ CanFail
    context(CanFail<Error>)
    suspend fun example(): Int = fail(Error)
    For more context on this see https://github.com/arrow-kt/arrow/pull/2797#issuecomment-1222239640 If you are interested in helping us decide please vote with one of those numbers or feel free to propose a new one or any question as thread comments to this post. Thanks!
    s
    s
    +8
    • 11
    • 25
  • t

    thanh

    08/22/2022, 1:40 PM
    anyone has experience/examples using Arrow in kmm, especially when interoperating with Swift?
    s
    j
    • 3
    • 5
  • s

    Sam

    08/22/2022, 3:25 PM
    This has probably been asked before, but I couldn’t find it from a quick search. Why doesn’t
    shift
    return
    Nothing
    ? It’s declared as
    suspend fun <B> shift(r: R): B
    but it could instead be
    suspend fun shift(r: R): Nothing
    The reason I ask is specifically because of this use case:
    var failure: MyFailure? = null
    val effect = eagerEffect<MyFailure, String> {
        failure?.let { shift(it) } // "Not enough information to infer type variable B"
        "some result"
    }
    The fix is to be explicit about the
    Nothing
    type, which feels super weird:
    val effect = eagerEffect<MyFailure, String> {
        failure?.let { shift<Nothing>(it) }
        "some result"
    }
    r
    s
    • 3
    • 8
  • l

    Lukasz Kalnik

    08/23/2022, 8:51 AM
    I want to init a class
    val
    property in the
    init
    block of a class based on some
    Either
    value. However, whenever I use any of the
    Either
    related functions like
    fold
    or
    either.eager
    block (which take a lambda as parameter) and I try to set the class property inside the lambda I get the error "Captured member variables initialization is forbidden due to possible reassignment". Is my only option really something like:
    myProperty = if (either.isRight()) either.value else defaultValue
    ?
    s
    s
    y
    • 4
    • 16
  • j

    Jörg Winter

    08/23/2022, 11:19 AM
    There are 2 repos in arrow-kt "arrow-inject" and "arrow-proofs" From the commits I guess that arrow-proofs is the way to go in the future, right ? ...so that instead of this
    fun createUser(bookInput: BookInput): ResponseEntity<ParsedBookResponse> =
       with(bookInput) {
          withParsedBook().fold(....)
    ...we can have this ?
    fun createUser(bookInput: BookInput): ResponseEntity<ParsedBookResponse> =
          withParsedBook().fold(....)
    ...by annotation + compiler plugin or Kotlin context receiver ? Currently I have this function:
    context(BookInput)
    fun withParsedBook(): Validated<NonEmptyList<String>, ParsedBook> {....}
    from this example I guess we still need that context<MyDependency> instead of with(MyDependency) ?
    r
    • 2
    • 3
Powered by Linen
Title
j

Jörg Winter

08/23/2022, 11:19 AM
There are 2 repos in arrow-kt "arrow-inject" and "arrow-proofs" From the commits I guess that arrow-proofs is the way to go in the future, right ? ...so that instead of this
fun createUser(bookInput: BookInput): ResponseEntity<ParsedBookResponse> =
   with(bookInput) {
      withParsedBook().fold(....)
...we can have this ?
fun createUser(bookInput: BookInput): ResponseEntity<ParsedBookResponse> =
      withParsedBook().fold(....)
...by annotation + compiler plugin or Kotlin context receiver ? Currently I have this function:
context(BookInput)
fun withParsedBook(): Validated<NonEmptyList<String>, ParsedBook> {....}
from this example I guess we still need that context<MyDependency> instead of with(MyDependency) ?
r

raulraja

08/23/2022, 12:56 PM
Hi @Jörg Winter, Arrow proofs is the current ongoing effort over a compiler plugin based on the new compiler FIR and k2. FIR is still not stable but when it comes out it will work on the IDE too. Proofs will focus on context receiver resolution. For example https://github.com/arrow-kt/arrow-proofs/tree/main/arrow-inject-compiler-plugin/src/testData/box/context-receivers Instead of
with
and a lambda you will be able to bring
@Provider
into the scope using
context<A, B, C, ...>
. for example:
j

Jörg Winter

08/23/2022, 1:01 PM
In that example, if f() had the dependencies as parameters, would they be injected into another receiving function that is called inside f() ?
r

raulraja

08/23/2022, 1:13 PM
They are exclusively injected when you summon their types with
context<A, B, ...>
. If you had declared instead those as context parameters to the function then when you call the function you have to summon them with
context
. It's possible to make it all implicit and just allow the call to resolve them magically based on what is missing, but we have not made a decision yet on whether that is a good idea or
context<A, B..
should be explicit.
View count: 17