b839a83bbf2e

Merge.
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Fri, 06 Dec 2019 21:00:13 -0500
parents 0b09e1b70887 (current diff) 18da0214d5a9 (diff)
children 2309743a485d a996dd9ad3eb
branches/tags (none)
files

Changes

--- a/DOCUMENTATION.markdown	Fri Dec 06 20:53:39 2019 -0500
+++ b/DOCUMENTATION.markdown	Fri Dec 06 21:00:13 2019 -0500
@@ -1888,7 +1888,7 @@
 
 ### `EXTREMA` (function)
 
-    (EXTREMA PREDICATE SEQUENCE)
+    (EXTREMA PREDICATE SEQUENCE &KEY (KEY #'IDENTITY))
 
 Return the smallest and largest elements of `sequence` according to `predicate`.
 
@@ -2123,7 +2123,7 @@
 
 ### `SH` (function)
 
-    (SH COMMAND &KEY INPUT OUTPUT (WAIT T))
+    (SH COMMAND &KEY INPUT (WAIT T) (RESULT-TYPE 'NULL))
 
 Run `command`, piping `input` to it, optionally returning its output.
 
@@ -2137,8 +2137,15 @@
   `input` must be a character input stream, a string, or `nil`.  If non-`nil`
   its contents will be sent to the program as its standard input.
 
-  `output` must be one of `:string`, `:stream`, or `nil`.  `:string` cannot be
-  used if `:wait` is `nil`.
+  `result-type` must be one of:
+
+  * `null`: output will be sent to `/dev/null` and `nil` returned.
+  * `stream`: output will be returned as a character stream.
+  * `string`: all output will be gathered up and returned as a single string.
+  * `list`: all output will be gathered up and returned as a list of lines.
+
+  If `wait` is `nil`, the only acceptable values for `result-type` are `null`
+  and `stream`.
 
   
 
--- a/src/sequences.lisp	Fri Dec 06 20:53:39 2019 -0500
+++ b/src/sequences.lisp	Fri Dec 06 21:00:13 2019 -0500
@@ -223,7 +223,7 @@
     (sequence (drop-while-seq predicate seq))))
 
 
-(defun extrema (predicate sequence)
+(defun extrema (predicate sequence &key (key #'identity))
   "Return the smallest and largest elements of `sequence` according to `predicate`.
 
   `predicate` should be a strict ordering predicate (e.g. `<`).
@@ -232,12 +232,16 @@
   respectively.
 
   "
-  (iterate (with min = (elt sequence 0))
-           (with max = (elt sequence 0))
-           (for el :in-whatever sequence)
-           (when (funcall predicate el min) (setf min el))
-           (when (funcall predicate max el) (setf max el))
-           (finally (return (values min max)))))
+  (iterate
+    (with min = (elt sequence 0))
+    (with min-val = (funcall key min))
+    (with max = (elt sequence 0))
+    (with max-val = (funcall key max))
+    (for el :in-whatever sequence)
+    (for val = (funcall key el))
+    (when (funcall predicate val min-val) (setf min el min-val val))
+    (when (funcall predicate max-val val) (setf max el max-val val))
+    (finally (return (values min max)))))
 
 
 (defun enumerate (sequence &key (start 0) (step 1) key)