Closed bentsherman closed 1 month ago
Closing in favor of flatMap
which is more idiomatic IMO:
workflow {
Channel.fromList( 1..15 )
.flatMap { n ->
if( n % 15 == 0 )
return [ "${n}: FizzBuzz" ]
if( n % 3 == 0 )
return [ "${n}: Fizz" ]
if( n % 5 == 0 )
return [ "${n}: Buzz" ]
return []
}
.view()
}
The
filterMap
operator is likebranch
but for a single output. It allows you to define a filtering condition and mapping expression in a single operator.I'm considering this alternative so that we might eventually phase out
branch
(andmultiMap
) so that we don't have to support the special closure-with-labels syntax that they use, which creates some challenges for some kinds of syntax errors.