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

    Bob Glamm

    04/27/2020, 7:19 PM
    wait, if I'm translating that in my head correctly that means the Scala equivalent signature is
    Option.fold[F, T, S](ifNone: => F[S], block: T => F[S])
    ?
    p
    • 2
    • 2
  • b

    Bob Glamm

    04/27/2020, 7:22 PM
    I'm not sure how I feel about two syntax mechanisms for effects -
    suspend () -> T
    vs.
    IO<T>
    p
    • 2
    • 2
  • b

    Bob Glamm

    04/27/2020, 7:24 PM
    Also, if I have
    suspend () -> T
    , how do I know which
    F
    is used in its isomorphism in
    Kind<ForF, T>
    ?
    r
    s
    • 3
    • 9
  • s

    simon.vergauwen

    04/28/2020, 10:29 AM
    No streams yet 😄
    👍 2
    a
    • 2
    • 3
  • p

    pakoito

    04/28/2020, 10:36 AM

    YET▾

    :arrow: 7
    👍 1
    😂 3
    m
    • 2
    • 2
  • v

    vjames19

    04/29/2020, 10:11 PM
    Hi! I'm really interested in functional error handling and the benefits that it brings by being explicit on the types of errors that can happen on each function. https://arrow-kt.io/docs/0.10/patterns/error_handling/ The example below showcases a generic example of different functions that implement some business logic and each has its own Set of distinct errors that can happen. These functions would later be use for implementing use cases, in which the use cases could also be reused across other use cases. I'm struggling to understand how to combine errors without losing type information and without having to resort to creating wrapper classes for each combination of errors.
    import arrow.core.Either
    
    // fictitious domain
    sealed class BusinessLogic1Error { 
      // all errors
    }
    
    sealed class BusinessLogic2Error {
      // all errors
    }
    
    sealed class BusinessLogic3Error {
      // all errors
    }
    
    fun businessLogic1(): Either<BusinessLogic1Error, String> = TODO()
    fun businessLogic2(): Either<BusinessLogic2Error, String> = TODO()
    fun businessLogic3(): Either<BusinessLogic3Error, String> = TODO()
    
    
    // use cases that use different business logic
    
    // approach 1
    // Union Type through wrapper class
    
    sealed class UseCaseError {
      class BusinessLogic1(val businessLogic1Error: BusinessLogic1Error): UseCaseError()
      class BusinessLogic2(val businessLogic2Error: BusinessLogic2Error): UseCaseError()
      // any other error that can be generated by a function used by this use case
      
    }
    fun useCase(): Either<UseCaseError, String> = TODO()
    
    // Pros:
    // Explicit and doesn't lose type information
    // Cons:
    // Doing this across multiple use cases gets unwieldy
    
    
    // approach 2
    fun useCase(): Either<Throwable, String> = TODO()
    
    // Loses all type info and its only serving as a placeholder to say that the function can fail
    Am I missing something? Is there a better approach?
    s
    • 2
    • 2
  • p

    pakoito

    04/30/2020, 2:22 AM
    what you want is union types, which is a plugin for arrow meta
    💯 4
    m
    • 2
    • 1
  • b

    Bob Glamm

    04/30/2020, 3:06 AM
    I need to get after the front-end guys I work with for having any instances of
    any
    in their code now
    p
    • 2
    • 3
  • t

    Thomas

    04/30/2020, 3:55 AM
    Hi, new Arrow user here maybe. But I can't find the API docs. When I go to https://arrow-kt.io/docs/0.10/apidocs/arrow-core/alltypes/index.html and look up the documentation for the
    Option
    class I get this (see image), but https://arrow-kt.io/docs/0.10/apidocs/arrow-core-data/arrow.core/-option/ has a truckload of functions available for Option (and IntelliJ agrees). Obviously I'm missing something... umm... obvious. But I cannot find the API documentation. Help a newbie out?
    m
    p
    r
    • 4
    • 7
  • i

    ivanmorgillo

    04/30/2020, 4:39 PM
    IO
    is the hardest sell and I need to do the heavy lifting learning it to be able to sell it 😂
    r
    • 2
    • 2
  • i

    ivanmorgillo

    04/30/2020, 6:20 PM
    fun areRemindersEnabled(): IO<Unit, Boolean> =
            storage.load<Boolean>(key)
                .handleError { false }
                .mapError { Unit }
    s
    • 2
    • 10
  • v

    Venkat

    04/30/2020, 6:23 PM
    Could anyone answer this SO question https://stackoverflow.com/questions/61530141/understanding-validated-applicative-in-kotlin-arrow-library
    s
    • 2
    • 27
  • i

    ivanmorgillo

    04/30/2020, 6:38 PM
    @melatonina I actually don't know. it seems I can't use
    IO<Boolean>
    anymore 🤔
    m
    • 2
    • 1
  • s

    Slackbot

    05/03/2020, 1:02 PM
    This message was deleted.
    m
    g
    • 3
    • 8
  • p

    pakoito

    05/04/2020, 9:47 AM
    I'll take a look later today!
    g
    • 2
    • 1
  • p

    pakoito

    05/04/2020, 10:50 AM
    validatorAE.validateEmailWithRules(user.email).bind()
    cityShouldBeValid(user).bind()
    loginShouldNotExit(user).bind()
    g
    • 2
    • 62
  • k

    kobby

    05/04/2020, 6:14 PM
    suspend fun one(): Either<Error, Int>
    suspend fun two(i: Int): Either<Error, Value>
    
    launch{
       one().fold(::Left, { right ->
           two(right) /// <- Kotlin is complaining that this needs to be in a coroutine scope
       }
    }
    Can you do this?
    p
    • 2
    • 8
  • d

    dnowak

    05/05/2020, 10:27 AM
    Hi, I’m trying to solve folling case. I have a
    List<IO<Either<E,A>>>
    and I want to stop on first success. How to do this with Arrow?
    s
    • 2
    • 26
  • s

    simon.vergauwen

    05/05/2020, 12:21 PM
    That’ll disappear if when we can detach
    fx
    completely from that using compiler plugins. I’m looking for other solutions as well in the meanwhile which play nicer with
    suspend
    . All suggestions very welcome.
    m
    • 2
    • 3
  • i

    ivanmorgillo

    05/07/2020, 2:40 PM
    let's say, I have a current implementation that looks like this:
    suspend fun loadInt(key: String): Int?
    The
    null
    is representing the absence of the value and that's why I was thinking about
    Either
    or
    Option
    , but then there is that problem. How would you imagine a migration to
    IO
    ? Something like this would work?
    fun loadInt(key: String): IO<Int>
    s
    • 2
    • 4
  • c

    CLOVIS

    05/07/2020, 3:01 PM
    Since the infrastructure is going through major changes at the moment, do you think it's the correct time to try to introduce Arrow to a project, or should i wait a few months until it calms down? (Taking into account that this project doesn't have any time limitation so there's no issue with waiting)
    r
    • 2
    • 4
  • b

    Bob Glamm

    05/07/2020, 3:02 PM
    I'm waiting for the churn to stop because there is no way I can introduce my team to one syntax and then switch over to another in the span of 6-12 months
    :yes: 3
    r
    • 2
    • 3
  • i

    ivanmorgillo

    05/07/2020, 4:36 PM
    then the question is even more weird: "Why should I use Rx/Coroutine AND IO?"
    p
    • 2
    • 1
  • i

    ivanmorgillo

    05/07/2020, 4:37 PM
    this is the question I get often and I can't answer yet: "Why should I invest in learning IO? what's the problem that's solving? show me a real world mobile startup problem that everybody has and I can only solve with IO"
    m
    • 2
    • 1
  • i

    ivanmorgillo

    05/07/2020, 5:25 PM
    unfortunately this kind of attitude is the root cause of the immediate emotional push back that FP triggers in most of the developers. it's not a technical problem. It's an emotional problem. the moment you make people feel stupid, it's over, you lost them and they will never forget. if you want to spread a mindset or a technology you have to make it accessible and accessible means also provide people with example that they can use tomorrow in their code base. I'm all about improving and growth mindset, but what @Satyam Agarwal said about sneaking Arrow in the code base will never work in most of the companies. 99.99% of them would just stop the PR from merging, because using Arrow is not your decision, but it's a team decision. what Arrow lacks at the moment is an effective and joyful way of showing how things improve with it. I have been talking about Arrow around the world for more that a year and people liked my talk because I give them examples, I give them tiny bits of discussion opportunities. I talk for an hour about Option, Either, Nel and Try and I never say "monad", because I know from experience that the moment I say "monad" or "effect" or "applicative" or "bifunctor" or "whatever fancy FP jargon word" I lose the audience. We need to make it easier if we want to spread it, and even if I can't understand how to use it, how can I ever start explaining to a junior dev!?
    r
    p
    +2
    • 5
    • 14
  • b

    Bob Glamm

    05/07/2020, 5:35 PM
    I can see proving totality using such a system. I'm not following how a system could also prove behavior, though
    r
    • 2
    • 6
  • j

    julian

    05/07/2020, 7:38 PM
    Oops! I Just unpinned a message by accident. Something to do with calling
    fix()
    in certain contexts? Sorry folks.
    r
    • 2
    • 1
  • p

    pakoito

    05/07/2020, 8:44 PM
    IO.unit.continueOn(Dispatchers.Main)
                .followedBy(IO.effect { render(ViewState.Error(it.message ?: "Ooops!")) })
    can be
    IO(Dispatchers.Main) { render(ViewState.Error(it.message ?: "Ooops!") }
    👍 1
    s
    • 2
    • 1
  • n

    Nico

    05/08/2020, 12:28 PM
    Hi! I intend to start a new KEEP to finally bring pattern matching to Kotlin, or at least have some discussion about it. I took the trouble to write up a draft, and I would love some feedback or contributions on it. I thought it would be popular with the Arrow community because it would make using the library's data types extremely natural. If you want to discuss this, I also posted in #language-proposals so ping me there!
    😍 9
    h
    r
    • 3
    • 17
  • v

    Venkat

    05/08/2020, 4:29 PM
    Is there any better way to cast nested Option like below. Option<Option<List<pair<String, Option<String>>>>
    b
    r
    • 3
    • 32
Powered by Linen
Title
v

Venkat

05/08/2020, 4:29 PM
Is there any better way to cast nested Option like below. Option<Option<List<pair<String, Option<String>>>>
b

Bob Glamm

05/08/2020, 4:49 PM
Start with
.flatten
to make it
Option<List<Pair<String, Option<String>>>
, and then maybe describe more about the use case?
Depending on what you want the outcome to be it may be possible to use
.traverse
or
.sequence
to get to Option<List<Pair<String, String>>> or even Option<Map<String, String>>
👍 1
v

Venkat

05/08/2020, 4:51 PM
I Just wants to access the right most Option<String> value
Flatten is not available for option. FlatMap is available
b

Bob Glamm

05/08/2020, 4:55 PM
.flatMap { it }
==
.flatten
Do you want to go from Option<Option<List<Pair<String, Option<String>>>> to List<String>?
v

Venkat

05/08/2020, 4:57 PM
Actually I'm writing test cases that needs to verify the value inside the string
So I have to cast way those Options to compare that string with my test string value
b

Bob Glamm

05/08/2020, 4:59 PM
.flatMap { it }.getOrElse(emptyList()).map { it.right() }.sequence().getOrElse(emptyList()) == listOf(/* expected */)
should at least be in the ballpark
To be honest, though, that type signature is .. difficult .. at best to work with. Usually there are intermediate transformations that deal with reducing the complexity of the type signature into something easier to work
👍 2
v

Venkat

05/08/2020, 5:01 PM
I already thought of doing like this but replacing None with empty list shadows the usage of Option
b

Bob Glamm

05/08/2020, 5:02 PM
Also, with this little context it's hard for me to suggest an efficient reduction or comparison for a test
v

Venkat

05/08/2020, 5:02 PM
Yes understood thanks 👍
r

raulraja

05/08/2020, 5:03 PM
There is no advantage of using Option over nullable types unless you are using polymorphism to target Option or a related transformer
👍 3
like OptionT
the only big diference is that in nullable types there is no flatMap or flatten because the environment already forbids from ??
but let and others are the same as map over option but in nullable types
b

Bob Glamm

05/08/2020, 5:05 PM
Will arrow-meta have a syntax for comprehensions over nullable types?
r

raulraja

05/08/2020, 5:05 PM
nullable types or suspension or other lang features that bakes a monad removes the need fro all the combinators up to Async
we can add that syntax already over nullable types if we wanted with suspension if you mean this:
val fa: A? = TODO()
val a: A by fa
v

Venkat

05/08/2020, 5:07 PM
@raulraja yes, I need to figure out a way to remove some level of nested option
r

raulraja

05/08/2020, 5:08 PM
@Bob Glamm all strict monads can shortcircuit a suspended continuation via their fold and if the unbiased casedis found raise an exception that the continuation handles itselfs and in this case would return null
b

Bob Glamm

05/08/2020, 5:08 PM
yes, that's exactly what I was hoping
r

raulraja

05/08/2020, 5:08 PM
we are removing the way binding happens
delegating to flatMap for all strict monads specializing it and making that faster
@Venkat you can eliminate the nesting of option in your expression inside an Fx block
v

Venkat

05/08/2020, 5:10 PM
Ok let me try
r

raulraja

05/08/2020, 5:10 PM
val fa: Option<A> = TODO()
Option.fx { 
  val a = !fa
  ... continue unfolding your nested list here
}
👍 3
and
!
every Option
your final result will be an option of your computation
!
will change to
by
👍 1
View count: 2