aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArun Isaac2023-10-14 23:38:58 +0100
committerArun Isaac2023-10-14 23:38:58 +0100
commite200e606900328bea1c237287d55ccd1f2b3ff2f (patch)
treee2d6c328f5e96554cce6c3336eb50f0a785245b7
parent82333d70f3a5dc64af99463516c5490bfd4e3894 (diff)
downloadrent-in-london-e200e606900328bea1c237287d55ccd1f2b3ff2f.tar.gz
rent-in-london-e200e606900328bea1c237287d55ccd1f2b3ff2f.tar.lz
rent-in-london-e200e606900328bea1c237287d55ccd1f2b3ff2f.zip
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.
-rw-r--r--rent.scm41
1 files 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))))))