From e200e606900328bea1c237287d55ccd1f2b3ff2f Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Sat, 14 Oct 2023 23:38:58 +0100 Subject: Use list-transduce. list-transduce allows us to see desired house listings as soon as they are found. We don't have to wait until all desired house listings are processed. * rent.scm (main): Use list-transduce. --- rent.scm | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/rent.scm b/rent.scm index 64ec3e0..6b64245 100644 --- a/rent.scm +++ b/rent.scm @@ -23,6 +23,7 @@ (srfi srfi-26) (srfi srfi-71) (srfi srfi-43) + (srfi srfi-171) (ice-9 match) (ice-9 regex) (ice-9 string-fun) @@ -460,21 +461,25 @@ Cycling distance to Wembley stadium: ~,1f km ;; - there is at least one tube station in the vicinity ;; - is not a bedsit ;; -;; Sort the listed houses newest advertisments last. -(list-houses - (filter (lambda (house) - (and (not (house-bills-included? house)) - (< (house-hours-live house) 100) - (not (house-shared? house)) - (<= (house-bedrooms house) 1) - (>= (house-rent house) 1200) - (<= (house-rent house) 1400) - (house-unfurnished? house) - (house-live? house) - (>= (house-maximum-tenants house) 2) - (not (null? (house-tube-stations house))) - (not (string-contains-ci (house-title house) "bedsit")))) - (sort (all-houses) - (lambda (house1 house2) - (> (house-hours-live house1) - (house-hours-live house2)))))) +;; Sort the listed houses newest advertisments first. +(format (current-output-port) + "~a houses~%" + (list-transduce (compose (tfilter (lambda (house) + (and (not (house-bills-included? house)) + (< (house-hours-live house) 100) + (not (house-shared? house)) + (<= (house-bedrooms house) 1) + (>= (house-rent house) 1200) + (<= (house-rent house) 1400) + (house-unfurnished? house) + (house-live? house) + (>= (house-maximum-tenants house) 2) + (not (null? (house-tube-stations house))) + (not (string-contains-ci (house-title house) "bedsit"))))) + (tlog (lambda (_ house) + (list-house house)))) + rcount + (sort (all-houses) + (lambda (house1 house2) + (< (house-hours-live house1) + (house-hours-live house2)))))) -- cgit v1.2.3