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

    Mickey Donaghy

    10/01/2020, 1:39 AM
    hi, I see
    Option
    is deprecated in 0.11. What's the migration path for functions that I was calling on
    Option
    (specifically
    traverse
    and
    foldMapM
    ) - is there an import that will make them available on nullable types or anything like that?
    s
    • 2
    • 8
  • v

    Vera van Mondfrans

    10/01/2020, 1:19 PM
    Hi, I’m struggling to think of a good way to combine
    Either
    with
    Flow
    when the flow can emit values before coming across something that should cause failure. For example:
    fun getNumbersThatAreNotEleven(n: Int): Either<ThatsElevenException, Flow<Int>> = 
      flow {
        for(i in 1..n) {
          if (i == 11) {
            // sacrilege, what do I do here?
          } else {
            emit(i)
          }
        }
      }
    a
    s
    • 3
    • 4
  • s

    Satyam Agarwal

    10/01/2020, 3:07 PM
    I am writing a test for a method whose implementation starts with
    parTupledN
    , it works if i use
    runBlocking
    to run the the test but not with
    runBlockingTest
    . Would be nice if its made possible.
    s
    • 2
    • 2
  • p

    Pueffl

    10/01/2020, 5:27 PM
    Hello! Can anybody show me, how to implement a functions that does an operation on a List given a function that does the operation on a single item in the context of IO and Either?
    fun delete(account: EmailAccount):  IO<Either<DatasourceFailure, Int>> {
    	// Implemented
    }
    
    
    fun delete(accounts: List<EmailAccount>): IO<Either<DatasourceFailure, Int>> {
    	???
    }
    I'm quite new to FP and the given documentation it is almost impossible to get the hang of it without having already done FP in another language.
    r
    • 2
    • 2
  • t

    thanerian

    10/01/2020, 7:22 PM
    I folks, testing this
    either<Error, List<String>> {
      remote.findByTerm(term)
    }.mapLeft { NetworkError }
    does not catch the exception, mock is configured in this way using mockito-kotlin
    given { runBlocking { remote.findByTerm(any()) } } willThrow { RuntimeException("BOOM!") }
    if I use
    Either.catch{}
    the exception is captured correctly and not propagated, is that the intended behavior?
    k
    r
    • 3
    • 7
  • d

    Daniel

    10/02/2020, 10:54 AM
    Hi, I'm trying to model api responses that can be either successful with a specific type of data, network/server errors with throwables, or an api error with a specific type of data. I want to only write the code handling network and server errors once, so I thought I could do something like
    sealed class Error<T> {
        data class Network(val throwable: Throwable): ApiError()
        data class Server(val throwable: HttpException): ApiError()
        data class Api(val response: T)
    }
    
    fun register(email: String, password: String): Either<Error<RegisterError>, AuthTokens>
    fun login(email: String, password: String): Either<Error<LoginError>, AuthTokens>
    I thought that would let me keep Error.Network and Error.Server the same everywhere, and substitute in different Error.Api's for different responses. The problem is that apparently Kotlin generics don't work like that. I would need to do
    sealed class Error {
        data class Network(val throwable: Throwable): ApiError()
        data class Server(val throwable: HttpException): ApiError()
        data class Api<T>(val response: T)
    }
    
    fun register(email: String, password: String): Either<Error, AuthTokens>
    fun login(email: String, password: String): Either<Error, AuthTokens>
    So I lose the ability to specify what kind of Error.Api I return. Is there a way to avoid this?
    a
    j
    • 3
    • 27
  • r

    rcd27

    10/03/2020, 7:01 AM
    @raulraja @Rachel why do we have type
    Nothing
    in this:
    fun <A> absurd(): (Nothing) -> A
    , but not
    Unit
    ? https://github.com/arrow-kt/Category-Theory-for-Programmers.kt/blob/master/src/main/ank/1.5-products-and-coproducts.md Like it is written in CTfP book: "In the category of sets and functions, the initial object is the empty set. Remember, an empty set corresponds to the Haskell type Void (there is no corresponding type in C++) and the unique polymorphic function from Void to any other type is called absurd" So
    Nothing
    in Kotlin is the initial type for everything else?
    s
    p
    r
    • 4
    • 5
  • c

    Ch8n

    10/03/2020, 4:34 PM
    Hello world 😅! .. I wanted to start learning arrow can anyone recommend where I should get started from , plus also if could suggest some commonly used arrow operations that everyone uses in their workflow would be great help.
    👏 2
    c
    r
    j
    • 4
    • 3
  • d

    Daniel

    10/04/2020, 4:57 PM
    I want to convert an
    Either<SomeError, SomeSuccess>
    to a
    SomeError?
    , discarding the SomeSuccess. Does a function like that exist in arrow? Right now I'm just doing the below, but I wanted to know if there is a more idiomatic way
    return when (result) {
                is Either.Left -> result.a
                is Either.Right -> null
            }
    d
    • 2
    • 5
  • j

    Jens Suhr

    10/05/2020, 7:38 AM
    Hi, I‘m currently migrating a project from IO to fx coroutines. It looks like everything works fine, but using
    evalOn
    (with any pool) seems to cause a deadlock in the IntelliJ debugger. This happens with both the whole application in debug mode and a single function in a test. Is there a wrapper or entry point I missed in the docs?
    s
    s
    k
    • 4
    • 15
  • j

    Jörg Winter

    10/05/2020, 1:43 PM
    Hi, so I included
    implementation("io.arrow-kt:arrow-optics:0.11.0")
    but my project doesn't seem to find the generated (where?) companion object functions. I am using a gradle project with IntelliJ and an "@optics" annotated data class ... do I have to include arrow-meta too ?
    r
    • 2
    • 5
  • m

    Marius Kotsbak

    10/06/2020, 10:07 AM
    Hmm, looks like Either's flatMap is not conforming to Scalas wrt. left type: https://arrow-kt.io/docs/apidocs/arrow-core-data/arrow.core/flat-map.html vs https://www.scala-lang.org/api/2.12.0/scala/util/Either.html#flatMap[AA%3E:A,Y](f:B=%3Escala.util.Either[AA,Y]):scala.util.Either[AA,Y] Scalas left just needs to be AA >: A, whereas in ArrowKt it needs to be the same.
    s
    s
    • 3
    • 21
  • r

    radekm

    10/06/2020, 11:18 AM
    Hi, I'm trying to rewrite
    IO
    code
    val func = IO {
        println("some effect")
    }
    func.retry(arrow.fx.Schedule.recurs(IO.monad(), 3))
    into coroutines but I can't find
    retry
    function which works on
    suspend () -> Unit
    . Does it exist or what's the alternative? Thanks
    s
    m
    • 3
    • 3
  • s

    Satyam Agarwal

    10/06/2020, 4:15 PM
    Hei. using
    0.11.0
    , it says
    Either.fx
    is deprecated, and use
    either { ... }
    but
    !
    or
    .bind()
    gives compilation error with
    either { .. }
    with
    arrow-fx-coroutines
    j
    p
    • 3
    • 3
  • p

    pakoito

    10/06/2020, 4:47 PM
    either { }
    is already a monad transformer because it allows suspend functions inside 😱
    😍 1
    j
    • 2
    • 16
  • v

    vio

    10/07/2020, 2:53 PM
    Hi all! I'm trying to define a function that will be called every hour, and I was looking into the arrow Timer, but can't figure out how to define it.. do you know where I can find any examples for Timer? Thank you!
    s
    • 2
    • 2
  • s

    sahil Lone

    10/08/2020, 6:20 AM
    Guys,  I had started a library last year to have a wrapper over Jackson for a type safe programming. Please have. a look at it, remarks are highly appreciated and. if you believe it can. be taken further please help to contribute https://github.com/sahlone/kson
    👏 3
    r
    • 2
    • 10
  • r

    radekm

    10/08/2020, 8:47 AM
    Hi, I have a question about definition
    suspend fun <A, B, C> retryOrElseEither(
      schedule: Schedule<A, B>,
      fa: suspend () -> A,
      orElse: suspend (Throwable, B) -> C
    ): Either<C, A>
    Why is input of
    schedule
    type
    A
    instead of
    Throwable
    ? I'm trying to use it but I can't figure how
    r
    j
    s
    • 4
    • 6
  • t

    than_

    10/08/2020, 12:23 PM
    Hi, is is possible to force optics generation for kotlin data class I don't own (it has companion object)?
    s
    • 2
    • 1
  • j

    Jorge Castillo

    10/10/2020, 9:08 AM
    Wrote this today 🙂 any feedback more than welcome 🙏 https://jorgecastillo.dev/tracking-side-effects-with-suspend
    👍 12
    r
    j
    • 3
    • 4
  • p

    pakoito

    10/10/2020, 1:00 PM
    and they all remain compatible with Either
    d
    d
    • 3
    • 12
  • m

    Mickey Donaghy

    10/12/2020, 7:48 AM
    Is there a function like
    Either#merge
    in Scala - an extension on
    Either<A, A>
    that returns
    A
    ? Shall I PR one?
    r
    y
    s
    • 4
    • 6
  • p

    Pueffl

    10/12/2020, 2:27 PM
    In your documentation on Validated under 'Improving the validation' you have the following example:
    val parallelValidate = Validated.applicativeNel<ConfigError>()
        .tupledN(v1.toValidatedNel(), v2.toValidatedNel()).fix()
        .map { (a, b) -> /* combine the result */}
    This example works, but it works only for values that are not optional?, so the current implementation is rather useless as you will not have Forms with every field mandatory (or Object with only mandatory fields when you create an instance in map {...} after validating each field. Should I consider this as a bug and report it or how would I validate a bunch of fields where some of them can be null?
    r
    j
    s
    • 4
    • 20
  • s

    stojan

    10/12/2020, 4:51 PM
    👁️ 5
    👏🏾 4
    🚀 7
    r
    k
    • 3
    • 8
  • k

    kioba

    10/12/2020, 6:14 PM
    is there an
    option { }
    continuation for nullable types similar to
    either {}
    ?
    r
    i
    • 3
    • 14
  • g

    genovich

    10/13/2020, 2:00 PM
    Hi! There was an article in this channel about how to replace IO or Observable, or Async with arrow fx. Something in context of continuation and suspend-functions
    r
    s
    • 3
    • 11
  • a

    Alex Johnson

    10/15/2020, 4:17 PM
    I was reading over the changes in https://github.com/arrow-kt/arrow-fx/pull/169 and was curious what the approach for error handling would be. Is the general approach to use something like this at any boundaries to exceptional libraries:
    suspend fun load(): Either<DomainError, DomainResult> = effectCatch(::errorHandler) {
        loadDomain()
    }
    I had used IO and used handleErrorWith to translate errors at my applications boundaries, but perhaps this is cleaner to mostly remove exceptions from my domain?
    s
    • 2
    • 3
  • s

    Satyam Agarwal

    10/15/2020, 6:30 PM
    when I do this for example :
    return either { 
        MyDomainObject.left().bind()
    }
    IDE shows me this :
    Returning type parameter has been inferred to Nothing implicitly. Please, specify type arguments explicitly to hide this warning. Nothing can produce an exception at runtime.
    on v0.11.0 with arrow-fx-coroutines.
    r
    a
    • 3
    • 5
  • d

    dephinera

    10/15/2020, 8:51 PM
    I just saw Option is deprecated as it is promoting bad coding style. However I'm curious are there really more downsides than upsides to make that decision. What's the experience with it? It was very useful for filterMap (what will the alternative be in this case?) and when using RxJava, where nu values are not allowed
    s
    k
    g
    • 4
    • 7
  • c

    carbaj0

    10/16/2020, 3:50 AM
    Hi, what would be the alternative for
    option.fx {}
    ? this cannot be achieved with nullable, right? should I replace it with
    either.fx { }
    ?
    s
    k
    • 3
    • 7
Powered by Linen
Title
c

carbaj0

10/16/2020, 3:50 AM
Hi, what would be the alternative for
option.fx {}
? this cannot be achieved with nullable, right? should I replace it with
either.fx { }
?
class DebitCardNumber private constructor(
    val number: String
) {
    companion object {
        private const val Mastercard = "^(?:5[1-5][0-9]{2}|222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)[0-9]{12}\$"

        suspend operator fun invoke(number: String): Either<Unit, DebitCardNumber> =
            if (number.matches(Mastercard.toRegex())) DebitCardNumber(number).right() else Unit.left()
    }
}
IO.fx {
            val validCardNumber = !effect { DebitCardNumber(cardNumber) }
            Either.fx<Unit, DebitCard> {
                VirtualDebitCard(
                    cardNumber = !validCardNumber,
                    accountNumber = accountNumber ?: "",
                    contractNumber = contractNumber ?: "",
                    cardStatus = cardStatus ?: "",
                    cancelIndicator = cancelReason ?: "",
                    cancelReason = cancelIndicator ?: "",
                    cardAlias = cardAlias ?: ""
                )
            }

        }.suspended()
s

simon.vergauwen

10/16/2020, 4:50 AM
It can be achieved for
nullable
, and someone is contributing it 🙂 https://github.com/arrow-kt/arrow-core/pull/251
c

carbaj0

10/16/2020, 6:44 AM
sealed class Shift<out T>
object Empty : Shift<Nothing>()
data class Result<T>(val result: T) : Shift<T>()
is this wrap needed?
k

kioba

10/16/2020, 7:19 AM
No, that wrap will be eliminated in the next commit, the guys helped me how to avoid this scenario, which means no wrapping performance penalty for continuation.
c

carbaj0

10/16/2020, 10:48 AM
👍
View count: 3