pipes
TOC »
Description
Besides the documentation procedure, this module exports three routines, the macros pipe and pipe* as well as the procedure flip*. The first macro takes a variable and a sequence of partial combinations, calls the first combination with the variable as additional left argument and hands the result successively to the next combination. For example
(pipe 3 (+ 1) (- 2) (* 5))
will return 10.
Sometimes its necessary to add the variable to the right of the argument list. To achieve this simply replace the combination's name, fn say, with (flip* fn): flip* flips the first argument of fn to the end, and thus is a generalisation of flip in (chicken base).
pipes
- pipesprocedure
- pipes symprocedure
documentation procedure: the first call shows the list of exported symbols, the second the documentation of sym.
pipe
- (pipe x (fn . xs) ...)syntax
calls each combination with the result of applying its combination to the left as first argument. In particular (pipe x (fn . xs)) is (fn x . xs) and (pipe x (fn . xs) (gn . ys)) is (gn (fn x . xs)).
pipe*
- (pipe* (fn . xs) ...)syntax
pipe as a procedure: (pipe* (fn . xs) ...) is (lambda (x) (pipe x (fn . xs) ...))
flip*
- flip* procprocedure
flips the arguments of proc by shifting the first one to the end.
Examples
((flip* list)) ; -> '() ((flip* list) 1) ; -> '(1) ((flip* list) 1 2) ; -> '(2 1) ((flip* list) 1 2 3 4) ; -> '(2 3 4 1) ((flip* map) '(0 1 2) add1) ; -> '(1 2 3) (pipe 5) ; -> 5 (pipe 5 (+ 1)) ; -> 6 (pipe 5 (- 10) (positive?)) ; -> #f (pipe 5 (- 10) (negative?)) ; -> #t (pipe 10 ((flip* list) 1 2 3 4)) ; -> '(1 2 3 4 10) (pipe 10 (list 1 2 3 4)) ; -> '(10 1 2 3 4)) (pipe '(0 1 2) ((flip* map) add1)) ; -> '(1 2 3)) (pipe 0 (list 1 2 3)) ; - > '(0 1 2 3)) (pipe 0 ((flip* list) 1 2 3)) ; - > '(1 2 3 0))
Requirements
none
Last update
Mar 28, 2019
Author
Repository
This egg is hosted on the CHICKEN Subversion repository:
https://anonymous@code.call-cc.org/svn/chicken-eggs/release/5/pipes
If you want to check out the source code repository of this egg and you are not familiar with Subversion, see this page.
License
Copyright (c) 2016-2019, Juergen Lorenz All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of the author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Version History
- 1.0
- initial import