[plt-scheme] for-each on a collection object members

From: Stephen De Gabrielle (spdegabrielle at gmail.com)
Date: Tue Jan 8 06:53:54 EST 2008


[Please excuse me if this is a silly question]

I want to 'map' or 'for-each' of a collection object which is a
collection of other objects, in the same way as I would over a regular
list (also filter from the list.ss List Utilities)

I can just turn the collection of objects into a list of objects, but
it seems there might be a better way? 'for-each-object-on-collection

  ;; collection of tuples
  (define TupleSet% (class object%
                      (define collection '())
                      ;; insert : alist -> void
                      (define/public (addTuple alist)
                        (set! collection (cons (new Tuple%
[initial-fields alist] ); tuple

                      ;; getTupleCount : -> number
                      (define/public (getTupleCount)
                        (length collection)
 ... and so on ...

Should I just make up the smalltalk iterator equivalents as needed?
eg; 'do:' from smalltalk

                      ;; do : tupleMethod -> result
                      (define/public (do tupleMethod)
                           (lambda (tuple) (send tuple tupleMethod) )

I'm searching for the 'right' way, or is this a silly question?



Stephen De Gabrielle

Posted on the users mailing list.