Skip to content

Commit

Permalink
Added #basicIterator and #iterator messages to Iterator.
Browse files Browse the repository at this point in the history
So it is polymorphic with objects providing iterators.
  • Loading branch information
juliendelplanque committed Oct 22, 2019
1 parent bb3999e commit 5841a08
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Iterators-Decorators/IteratorWithCollectionAPI.class.st
Expand Up @@ -237,6 +237,14 @@ IteratorWithCollectionAPI >> isNotEmpty [
^ self hasNext
]

{ #category : #accessing }
IteratorWithCollectionAPI >> iterator [
"To be polymorphic with objects providing an iterator.
No need to decorate twice.
"
^ self
]

{ #category : #testing }
IteratorWithCollectionAPI >> occurrencesOf: anObject [
"Answer how many of the receiver's elements are equal to anObject."
Expand Down
12 changes: 12 additions & 0 deletions src/Iterators/Iterator.class.st
Expand Up @@ -17,6 +17,12 @@ Iterator >> atEnd [
^ self hasNext not
]

{ #category : #accessing }
Iterator >> basicIterator [
"To be polymorphic with objects providing a basicIterator."
^ self
]

{ #category : #private }
Iterator >> checkHasNext [
self hasNext
Expand All @@ -41,6 +47,12 @@ Iterator >> isDecorator [
^ false
]

{ #category : #accessing }
Iterator >> iterator [
"To be polymorphic with objects providing an iterator."
^ self withCollectionAPI
]

{ #category : #accessing }
Iterator >> last [
^ (self decoratedBy: [ :x :y | y ] foldIt) next
Expand Down

0 comments on commit 5841a08

Please sign in to comment.