qi icon indicating copy to clipboard operation
qi copied to clipboard

`bundle*` -- multi-clause version of `bundle`

Open countvajhula opened this issue 2 years ago • 0 comments

Just like Racket's cond vs if and Qi's switch vs if or partition vs sieve, we'd like to have a multi-clause version of bundle:

(-< (~> (select 2 4) min)
    (~> (select 1 3) max))

could be written as:

(bundle (2 4) min max)

but, to be more explicit, and in case there are more than just two cases, it could be written as:

(bundle* [(2 4) min]
         [(1 3) max])

Here's a macro that does it:

(define-qi-syntax-rule (bundle* [(index ...) f] ...)
  (-< (~> (select index ...) f)
      ...))

Suggested by @jairtrejo .

countvajhula avatar Dec 07 '22 19:12 countvajhula