bentsherman / nf-boost

Experimental features for Nextflow
Apache License 2.0
31 stars 0 forks source link

Add `filterMap` operator #3

Closed bentsherman closed 1 month ago

bentsherman commented 3 months ago

The filterMap operator is like branch 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 (and multiMap) 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.

bentsherman commented 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()
}