]> gitweb.factorcode.org Git - factor.git/blobdiff - extra/bank/bank.factor
factor: trim using lists
[factor.git] / extra / bank / bank.factor
index 31a4b75eb2e985bddb92e7b55d992bd2671c0f92..fc214e05e31f3ecd8ddb46f68162f1295dba9e92 100644 (file)
@@ -1,6 +1,6 @@
 ! Copyright (C) 2008 Alex Chapman
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors calendar kernel math math.order money sequences ;
+USING: accessors calendar kernel math math.order sequences ;
 IN: bank
 
 TUPLE: account name interest-rate interest-payment-day opening-date transactions unpaid-interest interest-last-paid ;
@@ -15,7 +15,7 @@ C: <transaction> transaction
     over transactions>> push ;
 
 : total ( transactions -- balance )
-    0 [ amount>> + ] reduce ;
+    [ amount>> ] map-sum ;
 
 : balance>> ( account -- balance ) transactions>> total ;
 
@@ -54,7 +54,7 @@ C: <transaction> transaction
 : process-day ( account date -- )
     2dup accumulate-interest ?pay-interest ;
 
-: each-day ( quot: ( -- ) start end -- )
+: each-day ( ... quot: ( ... day -- ... ) start end -- ... )
     2dup before? [
         [ dup [ over [ swap call ] dip ] dip 1 days time+ ] dip each-day
     ] [
@@ -63,7 +63,7 @@ C: <transaction> transaction
 
 : process-to-date ( account date -- account )
     over interest-last-paid>> 1 days time+
-    [ dupd process-day ] spin each-day ;
+    [ [ dupd process-day ] ] 2dip swap each-day ;
 
 : inserting-transactions ( account transactions -- account )
     [ [ date>> process-to-date ] keep >>transaction ] each ;