https://kotlinlang.org logo
#codereview
Title
# codereview
e

elect

08/27/2019, 12:08 PM
would it be possible/make sense substitute constructs like this:
Copy code
var validated = true

        if (validated)
            validated = initProgram()
        if (validated)
            validated = initBuffer()

        return validated
With the kotlin
Result
or something more functional oriented?
s

Shawn

08/27/2019, 12:10 PM
this looks like it just simplifies down to `return initProgram() && initBuffer()`…
e

elect

08/27/2019, 12:11 PM
I know but there actually two additional points: 1) it's easier to debug, 2) sometimes other code comes in between
😕 1
r

reline

08/27/2019, 4:24 PM
would this work a little better for you? removes some if checks and makes one liners when using operators like
map { ... }
Copy code
var validated = true

validated = validated && initProgram()
validated = validated && initBuffer()

return validated
e

elect

08/30/2019, 8:41 AM
yes, thanks
j

Joris PZ

08/30/2019, 2:13 PM
Alternatively you could use a helper function,
Copy code
fun Boolean.and(block: () -> Boolean) = if (this) block() else false
and then
Copy code
val validated = true
return validated.and(::initProgram).and(::initBuffer)
4 Views