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

    CLOVIS

    02/10/2021, 8:20 AM
    I just saw the email announcement of
    value class
    and it sounds like something Arrow would be really interested in (immutable classes that have mutators that return copies). Do you have plans to use these features? They seem to clash with Lens, but maybe they could work well together?
    s
    s
    +2
    • 5
    • 22
  • c

    cavega

    02/12/2021, 4:03 AM
    Hello. Is there a way to transform an
    Either
    such that if
    Left
    meets some specific condition (i.e. filter out some error code that should not throw an error) the downstream Either via the fold operation gets routed to
    ifRight
    ? I did something like this (where Either<List<MyErrors>, <Data>>):
    return someService()
                .map { it.toEither().mapLeft {
                    it.filter { it.code != "some-failure-code" }
                } }
    But all that does in return an empty list of MyErrors to the downstream fold’s isLeft.
    s
    s
    • 3
    • 4
  • i

    Ifvwm

    02/12/2021, 1:36 PM
    is there Cont Monad in arrow-kt?
    r
    • 2
    • 6
  • r

    Roger Gilliar

    02/12/2021, 6:35 PM
    Hello, I just started to use arrow and I have some problems with the following code based and the validated example. I got this nicely working with the either monad (without the Rules class) but I would like to understand how to get rid of the fix and flatMap calls here and how to make this work for the accumulate strategy. Since validated is just a monoid flatMap would be not an option in that case, right ?
    fun validate(
       p: Player,
       i: Idea.OpenIdea,
       members: Eval<NonEmptyList<Member>>
    ): Either<NonEmptyList<ValidationError>, UnvalidatedPlayer> {
       return (Rules failFast {
           UnvalidatedPlayer(p, i)
               .let {
                   it.accountNotLocked(TeamDbRepository)
                       .flatMap { it.notMember().fix() }
                       .flatMap { it.hasEnoughSkills().fix() }
                       .flatMap { it.notTooManyUnfinishedIdeas().fix() }
                       .flatMap { it.budgetLimitNotReached().fix() }
                       .flatMap { it.suitableDepartment(TeamDbRepository).fix() }
                       .flatMap { it.skillsInLimit(members, TeamDbRepository).fix() }
                       .flatMap { it.teamNotComplete(members).fix() }
                        .flatMap { it.cantAddAgain(PlayerRepository).fix() }
               }
       })
    }
    r
    j
    +4
    • 7
    • 15
  • j

    julian

    02/15/2021, 7:56 PM
    When using Arrow with Android, how would one pass an instance like Either via an Intent, since Intent requires the Either to be Serializable or Parcelable?
    s
    s
    • 3
    • 16
  • r

    Roger Gilliar

    02/16/2021, 7:31 AM
    It seems that a class that is annotated with @optics can not be internal ? Is that true ?
    s
    • 2
    • 1
  • b

    Brad M

    02/20/2021, 11:24 PM
    Hey y'all, I saw that arrow now uses suspend functions to represent side effects, but I haven't found anything about the reasoning. Is it a marker? So if you call an impure suspend function, your function is now impure and thus must be suspended? (edit: marker, not sentinel)
    c
    s
    • 3
    • 4
  • g

    genovich

    02/21/2021, 8:35 PM
    Hey! Can anyone help me? Is there any way to run something like IO in in infinity loop with conditional exit? And if answer is tailRecM(), then can you explain how it works internally? Does it use lazy evaluation, or just build sequence until meet condition, and then run it?
    r
    s
    • 3
    • 24
  • c

    CLOVIS

    02/22/2021, 4:23 PM
    What is
    cancelBoundary()
    (in the last example of https://arrow-kt.io/docs/integrations/kotlinxcoroutines/) ?
    a
    s
    • 3
    • 3
  • j

    Jörg Winter

    02/24/2021, 5:52 PM
    Hi, dependency question: so to just work with the new effect-system (basics like either-computations using suspend functions, not the scheduling and concurrent API), I need to depend on
    arrow-fx
    and not necessarily on
    arrow-fx-coroutines
    ? (0.12-SNAPSHOT)
    🤔 1
    s
    • 2
    • 4
  • d

    dephinera

    02/27/2021, 11:21 AM
    I'm struggling with a case where I can have multiple kinds of errors. For example for one operation I could have NetworkError, EncryptionError and a GenericError (fallback for everything else uncovered by the other two). In other case I might have just NetworkError. I use Either to wrap the result. Left is used for errors, right for the success value. My question is is there a way I can specify that the left can be an arbitrary number of types (known at compile time)? Like Either can be Left or Right, is there something for more cases?
    p
    • 2
    • 9
  • m

    Marius Kotsbak

    03/01/2021, 9:15 AM
    I see code like this in our codebase:
    }.mapLeft { throw it }
    (on Either<Throwable, A>). Is this or should be part of the lib? I can't find out what rethrow() does, if it it is the same. Or something like getOrThrow.
    s
    s
    • 3
    • 4
  • i

    ibcoleman

    03/01/2021, 7:38 PM
    Realizing the answer may be “Don’t get yourself into such a situation.” I’m wondering if there’s a way to convert an
    Either<A, Either<A, B>>
    into an
    Either<A, B>
    (Sorry for the basic question)
    s
    r
    • 3
    • 4
  • s

    simon.vergauwen

    03/03/2021, 3:19 PM
    I can tell you
    0.12.0
    and
    0.13.0
    are coming really soon 😅 We're in the last 5% but you know how those go we don't have to explain to each other 😂
    🙇‍♂️ 8
    j
    s
    +2
    • 5
    • 5
  • o

    Orhan Tozan

    03/04/2021, 7:42 PM
    Let's say you have a algorithm function that acts like a pure function. This algorithm takes alot of time to compute, and thus adding suspend is normally recommended. However, in arrow world, suspend means that the function causes side effects, while this function doesn't at all (it is still pure, just takes alot of time). What should one do here?
    s
    j
    s
    • 4
    • 35
  • j

    Jimmy Alvarez

    03/04/2021, 7:49 PM
    If i want to perform an effect full operation like storing in a database, how could be the signature of the method I have an idea that is :
    suspend fun killSession(): Either<LowUnprotectedError, Unit>
    use void to represent the the effect full operation but feels wear, i think should be a better way to represent this kind of operations
    👌 2
    a
    r
    • 3
    • 4
  • m

    Marius Kotsbak

    03/05/2021, 9:53 AM
    What is the best way to run 2-3 different tasks in parallell (giving Either as result) with Arrow, i.e. it is not a list of equal operations?
    s
    • 2
    • 21
  • g

    Gopal S Akshintala

    03/05/2021, 10:26 AM
    My goal is to use Arrow in a java project at our company ‘Salesforce’ How can I use Kotlin Function type as a Data type within Java? For example: I have a typealias 
    typealias _Validator_<_ValidatableT_, _FailureT_> = _suspend_ (_ValidatableT_) -> _Either_<_FailureT_, Any?>
    Within Kotlin, I use it like this as a data type to assign to a lamda 
    val validateParent3X: _Validator_<_Egg_, _ValidationFailure_> = {...}
    But I cannot use typealias from Java. What is the idiomatic way to use this Function type as data type on Java? I see two unknows I have for java interoperability. 1. How can I idimotically refer a Function type 2. Function type being 
    suspend
    s
    p
    m
    • 4
    • 24
  • c

    carbaj0

    03/07/2021, 1:38 PM
    it isn´t able to resolve it
    s
    p
    • 3
    • 3
  • u

    123

    03/08/2021, 9:24 PM
    I'm fond of FP, but every time I think about adopting it into my backend project I find no practical use of it. Obviously, I mean advanced topics which are solved by Arrow, not standard Kotlin FP tools like
    data classes
    , high order funcs and etc. Any comprehensive open-source project (preferable Kotlin+Spring) which heavily uses Arrow (core, optics) you could recommend to dig in?
    👀 1
    c
    p
    • 3
    • 2
  • c

    CLOVIS

    03/08/2021, 10:01 PM
    Non-FP Kotlin makes easy uses of
    require()
    ,
    check()
    and
    error()
    to shortcut execution. Either is much more “precise” and “safe”, however I don't know how to write something as concise and readable:
    fun foo(param: Int) {
      require(param > 1) { "Some message here" }
    doSomething() ?: error("that's not possible")
    }
    I guess the
    either
    block should help with this, but I don't really see how to use it for these cases.
    s
    • 2
    • 10
  • a

    andries.fc

    03/09/2021, 7:30 AM
    What is going to happen now that JCenter is dead like doorknob? Is Arrow going to move to Maven Central?
    s
    r
    • 3
    • 2
  • b

    Benoît

    03/09/2021, 4:45 PM
    Hey guys, I'd like your advice on an issue I'm facing. So I have a screen that does an API call and shows a spinning wheel while the call is happening. All my API calls are represented as suspend functions. If I leave this screen while the call is ongoing, and come back to it, I would expect the spinning wheel to still be there, until the call is over. Alternatively, if I open another screen that depends on that same API call, I'd expect it to also show a spinning wheel, and update itself when the request comes back. In order to achieve this I need to, somehow, keep track that the call is out, and subscribe to its result rather than triggering a new call. With a non-functional approach, I would simply have a Flow in my repository and have multiple screens subscribing to it. But I don't want to do that cause it's smells like the kind of side-effects I wanna avoid. What is the best to go about this? Thanks!
    c
    r
    • 3
    • 9
  • d

    Dennis Tel

    03/09/2021, 6:30 PM
    👋 Hello! I've been using some functional programming languages like erlang/elixir/Clojure and recently started working at a company that uses Kotlin on the backend. Most of the code already makes use of (custom) Option/Maybe/Either types but I'm looking to take things a step further and make the database interactions more functional, probably using Arrow, but I don't know where to start. I'm assuming I need something like IO/Reader but is there any tutorial/blogpost/video that goes over this using Arrow? Any suggestions?
    c
    r
    • 3
    • 4
  • i

    ibcoleman

    03/09/2021, 11:40 PM
    Hi! I’ve been playing around with Validated, and based on advice here, wrote a simple little function that will return a ValidatedNel based on a single validation rule:
    suspend fun String.parseAgeString(): ValidatedNel<ValidationError, Int> =
            this.parseToInt().mapLeft{ Nel.just(ValidationError.InvalidAge) }
    But I’m having a hard time trying to figure out how to chain additional validation rules---say we have a Valid value but it has to be greater than 18 or it returns another distinct ValidationError.
    s
    r
    s
    • 4
    • 13
  • p

    pakoito

    03/10/2021, 4:47 PM
    nothing too long, it’d be like
    fun (Traverse<F>, Applicative<G>, Kind<F, Kind<G, A>>).sequence(): Kind<G, Kind<F, A>> =
      traverse(::it)
    c
    • 2
    • 9
  • a

    André Thiele

    03/11/2021, 11:46 AM
    Is support for KSP planned?
    r
    • 2
    • 4
  • j

    Jörg Winter

    03/11/2021, 5:01 PM
    Hi, is
    Validated.mapN(Semigroup.nonEmptyList(), ...)
    gone in 0.12 snapshot ?
    s
    • 2
    • 4
  • o

    Oliver Eisenbarth

    03/11/2021, 9:24 PM
    I'm thinking about getting "_Functional Programming in Kotlin - Sustainable code with Kotlin and Arrow" by_ Vermeulen, Bjarnason & Chiusano. But I fear that learning about IO and things that will be deprecated in the upcoming Arrow releases ,just to forget about them, will leave me confused. Would you recommend reading it anyways?
    r
    i
    m
    • 4
    • 5
  • c

    Cody Mikol

    03/11/2021, 11:28 PM
    Hey all, when using
    either<L,R> {  }
    I understand that you can bind getting some value to the context of that either, so I can do something like
    val foo = !service.getThingViaEither()
    What is the correct way to handle this in conjunction with validation where the return type doesn’t necessarily matter? Currently I’m doing something like
    !Either.conditionally(foo.isValid(), { Error("bar") }, { true }))
    I could also do something like
    val isValid = !checkFooValid(foo)
    but that also seems unnecessary as the isValid val will never be used
    c
    r
    • 3
    • 3
Powered by Linen
Title
c

Cody Mikol

03/11/2021, 11:28 PM
Hey all, when using
either<L,R> {  }
I understand that you can bind getting some value to the context of that either, so I can do something like
val foo = !service.getThingViaEither()
What is the correct way to handle this in conjunction with validation where the return type doesn’t necessarily matter? Currently I’m doing something like
!Either.conditionally(foo.isValid(), { Error("bar") }, { true }))
I could also do something like
val isValid = !checkFooValid(foo)
but that also seems unnecessary as the isValid val will never be used
c

CLOVIS

03/12/2021, 7:02 AM
Instead of
val isValid = !checkFooValid(foo)
you could just write
!checkFooValid(foo)
No need to declare a variable you're not using.
🔝 1
r

raulraja

03/12/2021, 9:27 AM
After 0.13 the only option is
checkFooValid(foo).bind()
invoke
,
not
,
componentX
are gone.
🔝 1
c

Cody Mikol

03/12/2021, 3:17 PM
thank you : )
View count: 3