Add "upply" (U-shaped apply, names are hard)
This commit is contained in:
parent
e6209fa8a4
commit
e209bfe130
5
d-.scm
5
d-.scm
@ -12,6 +12,7 @@
|
|||||||
partial
|
partial
|
||||||
argmin
|
argmin
|
||||||
iterate
|
iterate
|
||||||
|
upply
|
||||||
generator
|
generator
|
||||||
macro-expand))
|
macro-expand))
|
||||||
|
|
||||||
@ -72,6 +73,10 @@
|
|||||||
v
|
v
|
||||||
(iterate (1- n) f (f v))))
|
(iterate (1- n) f (f v))))
|
||||||
|
|
||||||
|
(define (upply a b cmp . fs)
|
||||||
|
(let ([arm-f (apply compose fs)])
|
||||||
|
(cmp (arm-f a) (arm-f b))))
|
||||||
|
|
||||||
;; Shamelessly ripped from https://wingolog.org/archives/2013/02/25/on-generators
|
;; Shamelessly ripped from https://wingolog.org/archives/2013/02/25/on-generators
|
||||||
(define (make-generator f)
|
(define (make-generator f)
|
||||||
(define tag (make-prompt-tag))
|
(define tag (make-prompt-tag))
|
||||||
|
5
test.scm
5
test.scm
@ -64,6 +64,11 @@
|
|||||||
(define value (iterate 2 1+ 3))
|
(define value (iterate 2 1+ 3))
|
||||||
(assert-equal 5 value)))
|
(assert-equal 5 value)))
|
||||||
|
|
||||||
|
(define-test-suite "upply"
|
||||||
|
(define-test "test"
|
||||||
|
(define value (upply -3 5 = abs 1-))
|
||||||
|
(assert-equal #t value)))
|
||||||
|
|
||||||
(define-test-suite "generator"
|
(define-test-suite "generator"
|
||||||
(define-test "test"
|
(define-test "test"
|
||||||
(define number-generator
|
(define number-generator
|
||||||
|
Loading…
Reference in New Issue
Block a user