aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2020-06-28 21:33:29 +0200
committerHugo Hörnquist <hugo@lysator.liu.se>2020-06-28 21:35:58 +0200
commitb81dc7e072697e2b204e7ed5ab7efaa673b5b6bd (patch)
treec37d8302380044554c8dd409dcacff195de4cb93
parentChanged HTML to include xcal instead of parameters. (diff)
downloadcalp-b81dc7e072697e2b204e7ed5ab7efaa673b5b6bd.tar.gz
calp-b81dc7e072697e2b204e7ed5ab7efaa673b5b6bd.tar.xz
Change calling for find-min.
-rw-r--r--module/srfi/srfi-41/util.scm2
-rw-r--r--module/util.scm16
2 files changed, 12 insertions, 6 deletions
diff --git a/module/srfi/srfi-41/util.scm b/module/srfi/srfi-41/util.scm
index 79cdbcb6..b1bc6f50 100644
--- a/module/srfi/srfi-41/util.scm
+++ b/module/srfi/srfi-41/util.scm
@@ -17,7 +17,7 @@
;; If all streams where empty, end the output stream
(if (null? streams)
stream-null
- (let* ((min other (find-min < stream-car streams))
+ (let* ((min other (find-min streams stream-car))
(m ms (stream-car+cdr min)))
(stream-cons m (interleave-streams < (cons ms other)))))))
diff --git a/module/util.scm b/module/util.scm
index 4dedc530..8cc0e032 100644
--- a/module/util.scm
+++ b/module/util.scm
@@ -7,7 +7,6 @@
#:re-export (define*-public fold-values)
#:export (for mod! sort* sort*!
mod/r! set/r!
- find-min
catch-multiple
quote?
re-export-modules
@@ -285,16 +284,17 @@
(comperator (get a)
(get b)))))
-;; Finds the smallest element in @var{items}, compared with @var{<} after
-;; applying @var{foo}. Returns 2 values. The smallest item in @var{items},
+;; Given {items, <} finds the most extreme value.
+;; Returns 2 values. The extremest item in @var{items},
;; and the other items in some order.
-(define (find-min < ac items)
+;; Ord b => (list a) [, (b, b -> bool), (a -> b)] -> a, (list a)
+(define*-public (find-extreme items optional: (< <) (access identity))
(if (null? items)
;; Vad fan retunerar man här?
(values #f '())
(fold-values
(lambda (c min other)
- (if (< (ac c) (ac min))
+ (if (< (access c) (access min))
;; Current stream head is smaller that previous min
(values c (cons min other))
;; Previous min is still smallest
@@ -303,6 +303,12 @@
;; seeds:
(car items) '())))
+(define*-public (find-min list optional: (access identity))
+ (find-extreme list < access))
+
+(define*-public (find-max list optional: (access identity))
+ (find-extreme list > access))
+
(define-public (filter-sorted proc list)
(take-while
proc (drop-while