1

When all booleans are set to true and I run startProcess() then it should be true and I want to execute the onFinished() method. How do I do this?

private var completed: BooleanArray = booleanArrayOf(false, false, false, false)

fun startProcess() {
    completed.all { it -> callback.onFinished() }
}
1
  • 1
    you mean like: if (completed.all { it }) { callback.onFinished() }? Commented Nov 22, 2018 at 11:29

2 Answers 2

6

Put the all in an if-condition, e.g.:

fun startProcess() {
  if (completed.all { it })
    callback.onFinished()
}

from the linked all-reference:

Returns true if all elements match the given predicate.

Sign up to request clarification or add additional context in comments.

Comments

1

Just use:

private var completed: BooleanArray = booleanArrayOf(false, false, false, false)
if (completed.all { it }) {
    callback.onFinished()
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.