Android-CleanArchitecture-Kotlin icon indicating copy to clipboard operation
Android-CleanArchitecture-Kotlin copied to clipboard

Suspending version of the fold operator?

Open shubham08gupta opened this issue 5 years ago • 0 comments

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?

shubham08gupta avatar Nov 27 '20 03:11 shubham08gupta