version 1.3
task gt_three {
input {
Int i
}
command <<< >>>
output {
Boolean valid = i > 3
}
}
workflow test_conditional {
input {
Boolean do_scatter = true
Array[Int] scatter_range = [1, 2, 3, 4, 5]
}
if (do_scatter) {
Int j = 2
scatter (i in scatter_range) {
call gt_three { i = i + j }
if (gt_three.valid) {
Int result = i * j
}
# `result` is accessible here as an optional
Int result2 = if defined(result) then select_first([result]) else 0
}
}
# Here there is an implicit `Array[Int?]? result` declaration, since
# `result` is inside a conditional inside a scatter inside a conditional.
# We can "unwrap" the other optional using select_first.
Array[Int?] maybe_results = select_first([result])
output {
Int? j_out = j
# We can unwrap the inner optional using select_all to get rid of all
# the `None` values in the array.
Array[Int] result_array = select_all(maybe_results)
# Here we reference the implicit declaration of result2, which is
# created from an `Int` declaration inside a scatter inside a
# conditional, and so becomes an optional array.
Array[Int]? maybe_result2 = result2
}
}