android10 / Android-CleanArchitecture-Kotlin

This is a movies sample app in Kotlin, which is part of a serie of blog posts I have written about architecting android application using different approaches.
https://fernandocejas.com/2018/05/07/architecting-android-reloaded/
4.68k stars 928 forks source link

Suspending version of the fold operator? #102

Open shubham08gupta opened 3 years ago

shubham08gupta commented 3 years ago

How about having a suspending version of the fold operator? Something like(please excuse the name):

suspend fun foldSuspend(fnL: suspend (L) -> Any, fnR: suspend (R) -> Any): Any =
        when (this) {
            is Left -> fnL(a)
            is Right -> fnR(b)
        }

Currently, it is:

 fun fold(fnL: (L) -> Any, fnR: (R) -> Any): Any =
        when (this) {
            is Left -> fnL(a)
            is Right -> fnR(b)
        }

Is it a good practice to keep 2 versions of the same function?