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
rx
  • u

    ursus

    12/25/2018, 7:16 PM
    its probably not pure right, I would use something with implicit "memory" like scan but it just doesnt work out, ill endup returning buffer from scan and then mapping to get the stuff from it, or returning a tuple of buffer and event, thats kind of silly
    a
    • 2
    • 5
  • l

    locke

    01/07/2019, 9:26 PM
    Anyone know how to
    switchOnNext
    against an
    Observable<Completable>
    ? Essentially I want to keep a subscription to the most recently emitted
    Completable
    emitted by an
    Observable
    , but for some reason that's proving challenging.
    l
    s
    • 3
    • 2
  • s

    Schadenfreude

    01/16/2019, 5:33 PM
    Hey guys, I’m trying to add a retry mechanism to a web call (made via RxJava + Retrofit) and I’m not sure what I should use - retry/When/Until or takeUntil. My problem with retry is that as far as I can tell it retries only on error, but my case is that I might get a PENDING or IN_PROGRESS status in the response body (the response itself being successful). So I need to retry the call let’s say 5 times or until I get a COMPLETED in the response.body(). Can anyone help me with that?
    k
    g
    • 3
    • 2
  • j

    jw

    01/20/2019, 4:14 AM
    it has the same behavior as publish that doesn't take a function except it's calling connect() and managing the subscription upstream automatically
    y
    • 2
    • 4
  • a

    arekolek

    01/29/2019, 10:55 AM
    interface Data
    
    data class Response(
            val data: List<Data>,
            val hasNextPage: Boolean,
            val nextPageId: Int?
    )
    
    fun makeRequest(nextPageId: Int): Single<Response> = TODO()
    
    fun getData(page: Int = 0): Flowable<Data> = makeRequest(page)
            .flatMapPublisher {
                Flowable.fromIterable(it.data)
                        .concatWith(it.nextPageId?.let(::getData) ?: Flowable.empty())
            }
    @ubu not sure how you want to do it without recursion though
    💥 1
    u
    • 2
    • 12
  • u

    ubu

    01/29/2019, 10:59 AM
    @arekolek, thanks. this is what I wanted to ask you about. Actually, does iterating over a list of data seem redundant? Why not just take last element of the collection?
    a
    • 2
    • 1
  • u

    ursus

    01/29/2019, 5:35 PM
    I think its called spread spreadout something like that
    u
    • 2
    • 2
  • g

    ghedeon

    02/01/2019, 11:29 AM
    Is there any way to say "switch back to caller thread"? For example, I want to wrap some callback call into a single, but the implementation of the callback is switching my thread to
    Main
    . As a result, the whole chain is now on the
    Main
    , which is not obvious, if you look at the declaration. Ex:
    ....
       .map { single_that_switches_the_thread_to_Main() }
       .map {}  // <--- NOT io
      .subscribeOn(io)
    So, I'd like to be able to tell to this
    single_that_switches_the_thread_to_Main()
    to switch to the caller thread, inside of it, not on the usage side.
    g
    r
    u
    • 4
    • 9
  • g

    ghedeon

    02/06/2019, 9:15 AM
    More a design question, but do you wrap all your events in
    Result
    class? In Repository as well? I see this idea popping up here and there and I just feel like it's a useless noise. There is a case when you woudn't want to break the stream on error (in UI layer, for example), but then I'd just catch the error and emit a special type of item. I'd rather do this, then wrap/unwrap the
    Result
    everywhere. Seems like google's influence with its primitive
    LiveData
    with no error handling support, where you have no choice other than adding exceptions to the data itself.
    c
    • 2
    • 2
  • u

    ursus

    02/14/2019, 5:34 AM
    Same here. Any opinions?
    g
    • 2
    • 2
  • u

    ursus

    02/15/2019, 3:32 PM
    id go for something like isInitialized.filter true.delay { ... }
    👍 1
    s
    • 2
    • 2
  • n

    nicka

    02/18/2019, 11:05 PM
    Hello all, I have a question about the best approach to handling conditional/if-else situation. I have an API response that will return one of three classes:
    Loading
    ,
    Error
    , or
    Finished
    — all of which inherit from a class called:
    NetworkState
    . If its Loading or Error, I want to update my UI appropriately. If its finished, I need to extract the data, do further transformations, then update the UI. I also need to perform a side-effect depending on one of the values returned. I can think of two ways to do this. Which of these is preferable? Is there a better third option? OPTION 1
    fetchFromApi().
      .map {
        when (it) {
          is Loading -> transformToLoadingView()
          is Error -> transformToErrorView()
          is Finished -> mapDataToUI(it.data)
      }.subscribe { view -> updateUi(view) }
    
    fun mapDataToUI(data: Data) {
      performSideEffect(data)
      transformDataToView(data)
    }
    OPTION 2
    val sharedResponse = fetchFromApi().share()
    
    Observable.merge(
      sharedResponse.ofType('Loading').map { loadingView },
      sharedResponse.ofType('Error').map { errorView },
      sharedResponse.ofType('Finished').map { transformDataToView(it) }
    ).subscribe { view -> updateUi(view) }
    
    sharedResponse.ofType('Finished').subscribe { performSideEffect(it) }
    g
    e
    u
    • 4
    • 10
  • f

    filipradon

    02/22/2019, 2:57 PM
    Guys, super quick question. Any idea why this test is not passing? I would expect
    firstOrError
    to throw error if subject has no values.
    @Test
        fun `assert tha behaviour subject behaves like i would expect to behave`() {
            BehaviorSubject.create<Boolean>()
                    .firstOrError()
                    .test()
                    .assertComplete()
        }
    s
    • 2
    • 5
  • j

    jw

    02/24/2019, 4:09 AM
    Because it's a representation of a higher order function that lets you pass around observable operators as data
    👍 1
    a
    • 2
    • 1
  • a

    adams2

    02/24/2019, 4:56 PM
    transforms_kt.kt
    d
    • 2
    • 5
  • u

    ursus

    02/26/2019, 1:02 PM
    is it the same functional argument as for not using exceptions, i.e mapping them to some monad / adt?
    g
    • 2
    • 7
  • u

    ursus

    02/26/2019, 4:30 PM
    @arekolek so you mean to rethrow basically?
    a
    • 2
    • 1
  • u

    ursus

    02/26/2019, 4:32 PM
    mostly what I mean is like this
    val request = apiRequestSingle()
    	.map { data -> Result.Success(data) }
    	.onErrorReturn { throwable -> Result.Error(throwable)}
    
    request
    	.flatMap { result ->
    		if(result is ResultSuccess) {
    			saveToDatabaseObservble(it)
    				.map { result }
    		} else {
    			Observable.just(result)
    		}
    	}
    	...
    vs basically
    apiRequestSingle()
       .flatMap { data -> saveToDatabaseObservable(data)
                          .map { data }
        }
    a
    • 2
    • 2
  • s

    Schadenfreude

    03/05/2019, 6:44 PM
    Hey guys, could you recommend a good book or online course for Rx (also maybe for functional programming with Kotlin/Java)?
    k
    g
    • 3
    • 3
  • e

    edwardwongtl

    03/15/2019, 5:47 AM
    Every
    doOnXXX()
    is intended for side effect, e.g. logging
    j
    • 2
    • 1
  • p

    Paul Woitaschek

    03/16/2019, 9:50 AM
    Also it shouldn't be switchMap x.toObservable bit switchMapCompletable
    i
    • 2
    • 1
  • u

    ursus

    03/17/2019, 1:15 AM
    why, just have the view as parameter
    i
    • 2
    • 3
  • j

    jw

    03/23/2019, 7:48 PM
    sounds like you want
    Completable
    t
    • 2
    • 1
  • u

    ursus

    03/25/2019, 9:45 PM
    but updating form automatically as db changes, under user's fingers, prolly not a good idea?
    g
    • 2
    • 2
  • f

    Fredrik Larsen

    04/07/2019, 9:22 PM
    If I have a network request with
    replay(1).autoConnect()
    and the stream errs, what is the best way to not cache that error? What I would like is basically to restart the stream.
    p
    u
    • 3
    • 4
  • u

    ursus

    04/08/2019, 8:12 PM
    If I have a call, that is potentially leaking (no way of removing the listener)
    g
    • 2
    • 8
  • u

    ursus

    04/08/2019, 8:13 PM
    and dispose its subscriptions, nothing leaks?
    g
    • 2
    • 7
  • i

    iex

    04/09/2019, 3:18 PM
    Untitled.kt
    g
    r
    • 3
    • 8
  • k

    kioba

    04/11/2019, 5:13 PM
    is that what you are looking for?
    w
    • 2
    • 8
  • u

    ursus

    04/14/2019, 3:29 AM
    @william yes you can do it without subject, just create anonymous object : ConnectivityManager.NetworkCallback(), and then wrap it in Observable.create { emitter -> ... }
    w
    • 2
    • 2
Powered by Linen
Title
u

ursus

04/14/2019, 3:29 AM
@william yes you can do it without subject, just create anonymous object : ConnectivityManager.NetworkCallback(), and then wrap it in Observable.create { emitter -> ... }
w

william

04/14/2019, 3:47 PM
sure that can be done but that doesn't really seem to gain anything - that just seems to be avoiding a subject for the sake of avoiding a subject
u

ursus

04/15/2019, 2:37 PM
Not really, I suggest you lookup use case and downsides of subject. Subjects are a bridge between imperative ansmd reactive, and they are hot and cannot dispose upstream. Which is precisely what you are gaining here
View count: 1