.TH "sequence" 3 "Oct 12, 2003" .SH Sequence .PP .B Inherits from: Object .SH Class Description .PP Sequences are used to loop or .I sequence over a group of objects\&. Typically, an .B Sequence instance is generated by using some method like .B OrdCltn \&'s .B eachElement \&. Then, within a loop, one can send .B next messages to the sequence until the end is reached (when the .B next method returns .B nil )\&. Finally, after using the sequence, you have to free the sequence object\&. .SH Warning .PP Using a sequence can lead to problems if, in sequencing over a collection, that collection is modified, e\&.g\&., as in the following : .RS 3 id item; .br id aSeq; .br .br aSeq = [aCol eachElement]; .br while ((item = [aSeq next])) [aCol add:something]; /* WRONG !!! */ .br aSeq = [aSeq free]; .br .RE .PP You may not modify a group of objects while sequencing over its contents\&. .SH Method types .PP .B Creation .RS 3 .br * copy .br * free .RE .PP .B Interrogation .RS 3 .br * size .RE .PP .B Accessing .RS 3 .br * next .br * peek .br * previous .br * first .br * last .RE .PP .B Printing .RS 3 .br * printOn: .RE .PP .B Performing .RS 3 .br * do: .RE .SH Methods .PP copy .RS 1 - .B copy .RE .PP Returns a copy of the sequence\&. Can be used independently of the original sequence\&. .PP free .RS 1 - .B free .RE .PP Frees the receiver, but not the objects in the collection being sequenced over\&. .PP size .RS 1 - ( unsigned ) .B size .RE .PP Returns the total number of items in the sequence\&. .PP next .RS 1 - .B next .RE .PP Returns the next object in the sequence if there is one and advances the sequence\&. When it reaches the end of the sequence, returns .B nil \&. .PP peek .RS 1 - .B peek .RE .PP Returns the next object in the sequence if there is one, but does not advance the sequence\&. When it reaches the end of the sequence, returns .B nil \&. .PP previous .RS 1 - .B previous .RE .PP Returns the object that was returned by the last .B next message\&. If there were no .B next messages since the sequence was created, or the sequence is empty, returns .B nil \&. Doesn\&'t affect the current position in the sequence\&. .PP first .RS 1 - .B first .RE .PP Returns the first object in the sequence, unlesss there are no members in the sequence, in which case it returns .B nil \&. Doesn\&'t affect the current position in the sequence\&. .PP last .RS 1 - .B last .RE .PP Returns the last object in the sequence, unlesss there are no members in the sequence, in which case it returns .B nil \&. Doesn\&'t affect the current position in the sequence\&. .PP printOn: .RS 1 - .B printOn :(IOD) .I aFile .RE .PP Prints a newline separated list of the objects in the sequence to .I aFile , by sending each individual object a .B printOn: message\&. Returns the sequence when there are no more elements left\&. .PP do: .RS 1 - .B do : .I aBlock .RE .PP Performs .I aBlock for the remaining members of a sequence\&. .I aBlock should take one argument, which is the element\&. Typically used as in, .RS 3 [[aDictionary eachValue] do:{ :each | [each show]; }]; .br .RE