aboutsummaryrefslogtreecommitdiff
path: root/algebraic-structures.foldable.scm
diff options
context:
space:
mode:
authorMasaya Tojo <masaya@tojo.tokyo>2024-06-14 02:25:10 +0900
committerMasaya Tojo <masaya@tojo.tokyo>2024-06-14 02:25:10 +0900
commit326a2a122e76dd9252558551d3f5e61c4014c2c1 (patch)
treee15c4afe27f696fec5a548b6f230b38111bebf5c /algebraic-structures.foldable.scm
parent9fc5da3b546ec101357fb826d7282a73cd790e83 (diff)
Fix foldable interfaces
Diffstat (limited to 'algebraic-structures.foldable.scm')
-rw-r--r--algebraic-structures.foldable.scm54
1 files changed, 27 insertions, 27 deletions
diff --git a/algebraic-structures.foldable.scm b/algebraic-structures.foldable.scm
index 3ab1f6e..be3d615 100644
--- a/algebraic-structures.foldable.scm
+++ b/algebraic-structures.foldable.scm
@@ -1,39 +1,39 @@
-(functor ((algebraic-structures foldable) (F (foldl foldr)))
- (foldl foldr length find any every ->list)
- (import (except scheme length) F
+(functor ((algebraic-structures foldable) (F (fold)))
+ (fold
+ length
+ count
+ any
+ every)
+ (import (except scheme length)
+ F
(only (chicken base) add1 call/cc))
(define (length xs)
- (foldl (lambda (acc _) (add1 acc))
- 0
- xs))
+ (fold (lambda (_ acc) (add1 acc))
+ 0
+ xs))
- (define (find p? xs)
- (call/cc
- (lambda (k)
- (foldl (lambda (acc e)
- (if (p? e)
- (k e)
- acc))
- #f
- xs))))
+ (define (count p? xs)
+ (fold (lambda (e acc)
+ (if (p? e)
+ (add1 acc)
+ acc))
+ 0
+ xs))
(define (any pred xs)
(call/cc
(lambda (return)
- (foldl (lambda (acc e)
- (cond ((pred e) => return)
- (else acc)))
- #f
- xs))))
+ (fold (lambda (e acc)
+ (cond ((pred e) => return)
+ (else acc)))
+ #f
+ xs))))
(define (every pred xs)
(call/cc
(lambda (return)
- (foldl (lambda (acc e)
- (or (pred e) (return #f)))
- #t
- xs))))
-
- (define (->list xs)
- (foldr cons '() xs)))
+ (fold (lambda (e acc)
+ (or (pred e) (return #f)))
+ #t
+ xs)))))