From b81dc7e072697e2b204e7ed5ab7efaa673b5b6bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Sun, 28 Jun 2020 21:33:29 +0200 Subject: Change calling for find-min. --- module/srfi/srfi-41/util.scm | 2 +- module/util.scm | 16 +++++++++++----- 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 -- cgit v1.2.3