qi
qi copied to clipboard
`bundle*` -- multi-clause version of `bundle`
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 .