(moduleiterator-interfacemzscheme
(require"../private/require.ss")
(require-contracts)
(require-class)
(provideiterator<%>iterator/citerator?indexed-iterator<%>indexed-iterator/cindexed-iterator?counted-iterator<%>counted-iterator/ccounted-iterator?
)
;; iterator<%> : Interface
;; The interface for objects of type (Iterator Elem) for any type Elem,
;; representing iterators over collections of any element type.
(defineiterator<%>
(interface ()
;; (send (Iterator Elem) end?) : Boolean
;; Reports whether the iterator has reached the end.
end?;; (send (Iterator Elem) element) : Elem
;; Produces the element at the iterator's current position.
;; It is an error if the iterator is at the end of the collection.
element;; (send (Iterator Elem) next) : (Iterator Elem)
;; Produces an iterator at the next position.
;; It is an error if the iterator is at the end of the collection.
next
))
;; iterator/c : FlatContract
;; Recognizes iterators.
(defineiterator/c (is-a?/citerator<%>))
;; iterator? : Any -> Boolean
;; Reports whether a value is an iterator.
(define (iterator?v)
(is-a?viterator<%>))
;; indexed-iterator<%> : Interface
;; The interface for objects of type (IndexedIterator Key Elem)
;; representing iterators over indexed collections with the given
;; key and element types.
;; An (IndexedIterator Key Elem) is also an (Iterator Elem).
(defineindexed-iterator<%>
(interface (iterator<%>)
;; (send (IndexedIterator Key Elem) key) : Key
;; Produces the key at the iterator's current position.
;; It is an error if the iterator is at the end of the collection.
key
))
;; indexed-iterator/c : FlatContract
;; Recognizes indexed iterators.
(defineindexed-iterator/c (is-a?/cindexed-iterator<%>))
;; indexed-iterator? : Any -> Boolean
;; Reports whether a value is an indexed iterator.
(define (indexed-iterator?v)
(is-a?vindexed-iterator<%>))
;; counted-iterator<%> : Interface
;; The interface for objects of type (CountedIterator Elem)
;; representing iterators over collections where elements
;; of the given type have a count of the number of appearances
;; in the collection.
;; A (CountedIterator Elem) is also an (Iterator Elem).
(definecounted-iterator<%>
(interface (iterator<%>)
;; (send (CountedIterator Elem) count) : Integer
;; Produces the count for the current element.
;; It is an error if the iterator is at the end of the collection.
count
))
;; counted-iterator/c: FlatContract
;; Recognizes counted iterators.
(definecounted-iterator/c (is-a?/ccounted-iterator<%>))
;; counted-iterator? : Any -> Boolean
;; Reports whether a value is a counted iterator.
(define (counted-iterator?v)
(is-a?vcounted-iterator<%>))
)