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

    Jascha Smacka

    06/18/2021, 2:28 PM
    Also, we are using Arrow in Spring and a hexagonal (Ports&Adapters) Architecture and I'm really wondering, where we best draw the line between "Here Spring gouverns dependency injection" and "Here we do DI the Arrow way (with receivers)". Currently our team is leaning towards "Use Spring everywhere down to the service layer" but I would be very interested if someone already has some experience with this..?
    👍 2
    r
    o
    s
    • 4
    • 18
  • d

    Dorian Codes

    06/22/2021, 3:40 PM
    Hi! I'm starting to use arrow for data validation (I'm not super familiar with the library, but I used cats/scalaz libraries for scala in the past). Following the docs about Validated I noticed that this snippet doesn't compile
    data class Config(val map: Map<String, String>) {
      suspend fun <A> parse(read: Read<A>, key: String) = either<ConfigError, A> {
        val value = Validated.fromNullable(map[key]) {
          ConfigError.MissingConfig(key)
        }.bind()
        val readVal = Validated.fromNullable(read.read(value)) {
          ConfigError.ParseConfig(key)
        }.bind()
        readVal
      }
    In particular I wasn't able to call
    bind()
    from a
    Validated
    . Is that something I am missing? Also I noticed that
    bind()
    is not listed among the functions for
    Validated
    in the docs. I'm using
    arrow-core version 0.11.0
    c
    • 2
    • 3
  • m

    Miłosz Korman

    06/24/2021, 1:55 PM
    Hi! I’m playing around with refined types and anticipated intellij to show me the red squiggly line whenever providing illegal constant value as an argument to invoke function, but the ide doesn’t really show me an error only in console when building the project. I’m working at 2021.1.2 version of intellij. Can I do something about it?
    t
    r
    • 3
    • 2
  • p

    Pedro Sena

    06/28/2021, 7:25 PM
    is it omitted on the docs for simplicity or there is a workaround to not declare it ?
    s
    • 2
    • 2
  • k

    kierans777

    06/29/2021, 4:05 AM
    Not an arrow question per se, but is there a way to have a function return a function with a generic type in Kotlin/Arrow. I want to do
    fun doSomething(): ((Class<T>) -> T) -> T
    However because lambda expressions can't have generic types, this doesn't compile for me.
    s
    m
    • 3
    • 44
  • d

    ds3fdfd3

    06/29/2021, 1:31 PM
    Hi, is there a way to call suspend function inside
    eval's
    map and flatmap. I have this code but it doesn't compile as
    doSomething()
    can only be called withing coroutine body.
    import arrow.core.Eval
    import kotlinx.coroutines.runBlocking
    
    fun main(): Unit = runBlocking {
        Eval.now(10)
            .map { doSomething() }
            .value()
    }
    
    private suspend fun doSomething(): Int {
        println("do something")
        return 20
    }
    s
    • 2
    • 6
  • s

    stojan

    06/30/2021, 8:09 AM
    https://blog.jetbrains.com/kotlin/2021/06/kotlin-features-survey-edition-2/
    :kotlin-intensifies: 5
    s
    s
    m
    • 4
    • 13
  • a

    Alvaro Blazquez checa

    06/30/2021, 9:04 PM
    Hola!!. I have a question regarding arrow upgrade to 0.13.1
    r
    t
    s
    • 4
    • 9
  • s

    Srki Rakic

    07/05/2021, 5:15 PM
    Hi 👋 . What is the proper way to get a list of errors
    List<Error>
    out of
    List<Either<Error, Result>>
    ?
    👍 1
    s
    • 2
    • 2
  • d

    Daniel Ryan

    07/06/2021, 3:34 PM
    Sorry for the basic question. Given I have a list of identifiers
    val ids = listOf(1, 2, 3)
    and I have a function that returns a valid thing for a given identifier
    fun getThing(id: String) : Either<String, Thing?>
    what is the best way to execute the getThing function for all ids in the list until a Thing is found, or an either.left is encountered? Traverse is close to what I need, but it will involve unnecessary database calls; I will like to exit processing as soon as a match is found.
    k
    f
    • 3
    • 3
  • j

    julian

    07/06/2021, 7:40 PM
    What method should be used to perform a side-effect using the value of the left side of an
    Either
    ? I could use
    fold
    . But that doesn't seem quite right since
    fold
    `s intent seems to be more on producing a value, not performing side-effects.
    👀 1
    s
    • 2
    • 4
  • c

    CLOVIS

    07/08/2021, 4:48 PM
    How will Context Receivers (https://github.com/Kotlin/KEEP/blob/context-receivers/proposals/context-receivers.md) impact Arrow? In particular, they mention Monoid as a use case, and that looks really close to what typeclasses were trying to achieve
    r
    • 2
    • 3
  • l

    Lidonis Calhau

    07/10/2021, 10:07 PM
    I tried arrow refined-types and I wonder if there is a way to combine them with Validated from the core library
    r
    • 2
    • 2
  • s

    Sergei Zubov

    07/14/2021, 12:40 PM
    Hello! I'm trying to understand how to mark side effects correctly. Documentation to Arrow Fx describes using
    suspend () -> A
    instead of
    IO<A>
    . Does this literally means that signature of the function that produces a side-effect should be
    suspend () -> A
    , or it can be
    suspend (parameter1, parameter2...) -> A
    ? Which one is correct and why:
    data class Message(val content: String)
    suspend fun sideEffectProducer(message: Message) = println(message)
    or
    data class Message(val content: String)
    suspend fun Message.sideEffectProducer() = println(this)
    And a follow-up question - how functions with side effects differ from pure functions that use
    either
    block and
    .bind()
    results? Both of them are
    suspend
    👍 1
    s
    • 2
    • 6
  • c

    carbaj0

    07/15/2021, 8:10 AM
    when i see the photo profile i think that someone was impersonating Simon
    :trollface: 3
    🤣 1
    s
    t
    s
    • 4
    • 3
  • s

    simon.vergauwen

    07/15/2021, 10:58 AM
    Hahaha, ye I guess I have to win everyone’s trust again looking like a total stranger 😂
    😂 4
    s
    r
    s
    • 4
    • 5
  • s

    Sergei Zubov

    07/16/2021, 10:36 AM
    Hello! Is there a reason why I should write my code using extension functions, not regular member ones? I understand that they are resolved in compile-time, is this it? Extension functions allow the compiler to build and optimise the whole flow rather than treat the code as a set of objects that can interact with each other? Or is it just a question of style?
    r
    s
    t
    • 4
    • 11
  • p

    Peter

    07/19/2021, 10:54 PM
    hi - wondering if
    either
    lazy blocks do not play well with the coroutine dump generator? i use (the scarcely documented) way of sending a process a 5 signal to get a coroutine dump (similar to 3 for a thread dump) … the line numbers often don’t make sense (larger than the file contains, refers to desugared code?). in every case i believe the coroutine is suspended somewhere within the
    either
    block (though hard to be 100% sure given the line number inaccuracy) the top of the coroutine stack frames is always the function containing the
    either
    block, i was hoping to see more detail
    s
    • 2
    • 2
  • a

    Andrei Bechet

    07/22/2021, 11:40 AM
    Hello 🙂 I am trying to understand a bit how to use
    either
    with coroutines in Springboot and I am not sure I fully understand what’s happening. Take for example this code:
    suspend myServiceFunction() = either {
      val r1 = someApiCall(...).bind() 
        // Either<Fail,Res1>
      val r2 = someOtherApiCall(...).bind()
        // Either<Fail,Res2>
    
      combineOperation(r1, r2) // Either<Fail, Res2>
    }
    My question is the following: how can we best make
    someApiCall
    and
    someOtherApiCall
    run in parallel? Is the
    bind
    for obtaining
    r2
    is waiting for
    r1
    to first get returned? Thanks 🙂
    s
    • 2
    • 44
  • c

    carbaj0

    07/25/2021, 10:11 AM
    hi! I've wondered if the optics library can be implemented with a compiler plugin instead of actual code generation. If this was possible, what pros and cons have over the current implementation
    s
    • 2
    • 4
  • m

    Marko Novakovic

    07/26/2021, 7:48 AM
    can somebody link me real world example of using arrow and functional programming? not something that just uses
    Either
    and calls itself functional programming nor something too complicated for purposes of showing theory in practice.
    s
    s
    +5
    • 8
    • 40
  • o

    Oliver Eisenbarth

    07/28/2021, 3:05 PM
    Hi, afaik one only needs to use Environment() for unlocking Arrow FX Coroutines, if there's no suspended entry point in the environment. Ktor and Spring Boot are supposed to have such, but I don't find any suspended router functions. Do I have to rely on the fancy banner saying "Co-Routines included!" to decide, if I need to use Environment() or not, or am I missing something? 🤔
    s
    • 2
    • 12
  • r

    rcd27

    07/29/2021, 10:13 AM
    Hello, in the code below I'm expecting
    .getOrHandle
    to return
    List<ContractorTas>
    , however compiler thinks there is
    List<Any>
    . What am I doing wrong?
    s
    y
    j
    • 4
    • 22
  • s

    simon.vergauwen

    08/01/2021, 8:15 PM
    I did some work on the Arrow Fx docs, and wrote/improved some parts. In case any is interested, feedback is also welcome ofc 🙂 https://github.com/arrow-kt/arrow/pull/2460/files
    :arrow: 2
    🙌 2
    🙌🏼 1
    👀 2
    p
    o
    • 3
    • 6
  • l

    Lidonis Calhau

    08/03/2021, 2:50 PM
    Hello, Is there a function to combine two validated variable to check is they are compatible with each other Maybe a function like this to allow some check with both values
    Validated<ValidationError, Enum1>, Validated<ValidationError, Enum2> -> Validated<Nel<ValidationError>, Pair<Enum1, Enum2>>
    s
    s
    • 3
    • 12
  • p

    Peter

    08/03/2021, 8:53 PM
    hi - i’m wondering why
    Either.catch
    is strict in evaluating it’s supplied function, is there a way to catch an Exception from an effect? eg
    suspend findThing(): Thing {} 
    
    Either.catch { findThing() } // ???
    s
    c
    • 3
    • 42
  • r

    rcd27

    08/04/2021, 8:24 AM
    I've turned back-end responses into
    Either
    monad from
    Retrofit
    interfaces. What do you think I've recently got from my partner? Brilliant idea: to skip handling each
    Left
    and just throw Exceptions. Remember the song?: lonelyyyy, I'm sooo loonelyyyy 😭
    :500: 3
    😅 9
    s
    o
    • 3
    • 3
  • r

    rcd27

    08/13/2021, 9:34 AM
    Hello everyone, I'm thinking of a project, main idea is about processing an image with
    OpenCV
    . I believe that I should implement something reactive + FP: imagine there is a bar where we can "just add new processing operation". This will result in a "list of operations", applied:
    rawImage -> op1-> op2 -> op3 -> processedImage
    . where all
    opX
    take result of the previous one. That would be great to memoize the result of operations, so that if I change some characteristics in
    op3
    for example (each operation has its own arguments), that wouldn't lead to recomputation of
    op1
    and
    op2
    . Which way should I dig in, how do you think? I think this is ideal for FP, what do you say?
    r
    • 2
    • 4
  • n

    noone

    08/14/2021, 7:51 PM
    Is there a book for Arrow?
    r
    • 2
    • 3
  • d

    Dario Valdespino

    08/15/2021, 5:47 PM
    [Solved] A bug in the Kotlin compiler caused issues with inline classes inside
    crossinline suspend
    functional parameters. Fixed in Kotlin 1.5.30-RC. Is it a known bug that
    either {}
    does not work properly with
    value
    classes? For example, the following code:
    @JvmInline
    value class Metadata(val map: Map<String, String>)
    
    fun reproduceBug() = either<Unit, Metadata>{
      Metadata(emptyMap())
    }
    Whenever I use debug to see the result of the function, it will contain a
    Right({})
    , meaning that the right value actually contains the underlying
    Map
    instead of the
    Metadata
    wrapper. This causes a
    ClassCastException
    in runtime when using
    bind
    . Am I missing something?
    s
    • 2
    • 3
Powered by Linen
Title
d

Dario Valdespino

08/15/2021, 5:47 PM
[Solved] A bug in the Kotlin compiler caused issues with inline classes inside
crossinline suspend
functional parameters. Fixed in Kotlin 1.5.30-RC. Is it a known bug that
either {}
does not work properly with
value
classes? For example, the following code:
@JvmInline
value class Metadata(val map: Map<String, String>)

fun reproduceBug() = either<Unit, Metadata>{
  Metadata(emptyMap())
}
Whenever I use debug to see the result of the function, it will contain a
Right({})
, meaning that the right value actually contains the underlying
Map
instead of the
Metadata
wrapper. This causes a
ClassCastException
in runtime when using
bind
. Am I missing something?
s

simon.vergauwen

08/16/2021, 11:51 AM
Hey @Dario Valdespino, Yes, that’s exactly what is happening since the
value class
doesn’t exist at runtime. IIRC this bug is related to
suspend
+
value class
and is “unrelated” to the encoding inside
either { }
. For this reason I’m currently not using
value class
yet in production (😞). So this is fixed in 1.5.30?
d

Dario Valdespino

08/16/2021, 12:33 PM
Yep, I had to update to the 1.5.30-RC but it works as expected
👍 1
s

simon.vergauwen

08/16/2021, 12:42 PM
Cool, thanks for the update. That version should be released before we release Arrow 1.0.0 soon 🙂
👍🏼 1
View count: 7