Add multi-compose.

This commit is contained in:
Sergiu Ivanov 2020-12-18 12:58:43 +01:00
parent 0733e6ab0c
commit 03dc7eb0e5
1 changed files with 16 additions and 0 deletions

View File

@ -121,3 +121,19 @@
((compose-8 n->s add1 add1 add1 add1 add1 add1 s->n) "3") "9")
(check-equal?
((compose-9 n->s add1 add1 add1 add1 add1 add1 add1 s->n) "3") "10"))
(define-syntax (multi-compose stx)
;; Implementation by Sorawee Porncharoenwase.
(syntax-parse stx
[(_ f:expr g:expr)
#'(compose f g)]
[(_ f:expr funcs:expr ...)
#'(compose f (multi-compose funcs ...))]))
(module+ test
(check-equal? ((multi-compose add1
(λ ([x : Number]) (* x 3))
add1
(λ ([x : Number]) (+ x 2)))
3)
19))