drym-org / qi

An embeddable flow-oriented language.
58 stars 12 forks source link

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

Open countvajhula opened 1 year ago

countvajhula commented 1 year ago

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 .