would it be possible/make sense substitute constru...
# codereview
e
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
this looks like it just simplifies down to `return initProgram() && initBuffer()`…
e
I know but there actually two additional points: 1) it's easier to debug, 2) sometimes other code comes in between
😕 1
r
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
yes, thanks
j
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)