-
Notifications
You must be signed in to change notification settings - Fork 4
/
pipeline.ss
31 lines (26 loc) · 952 Bytes
/
pipeline.ss
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#lang scheme/base
(require "base.ss")
; Procedures -------------------------------------
; (listof stage) target arg ... -> result
;
; where stage : continue arg ... -> result
; continue : arg ... -> result
; target : arg ... -> result
; arg : any
; result : any
;
; Calls a procedure via a pipeline. The result returned is either
; the result of the procedure or that of the last stage invoked.
(define (call-with-pipeline pipeline procedure . args)
(define (pipe pipeline . args)
(if (null? pipeline)
(apply procedure args)
(let ([stage (car pipeline)]
[success
(lambda args
(apply pipe (cdr pipeline) args))])
(apply stage (cons success args)))))
(apply pipe pipeline args))
; Provide statements ---------------------------
(provide/contract
[call-with-pipeline (->* ((listof procedure?) procedure?) () #:rest any/c any)])