Product SiteDocumentation Site

5.3.8.11. section


>>-section(start-+--------+-)----------------------------------><
                 +-,items-+

Returns a new queue (of the same class as the receiver) containing selected items from the receiver. The first item in the new queue is the item corresponding to index start in the receiver. Subsequent items in the new queue correspond to those in the receiver (in the same sequence). If you specify the whole number items, the new queue contains only this number of items (or the number of subsequent items in the receiver, if this is less than items). If you do not specify items, the new queue contains all subsequent items from the receiver. The receiver queue remains unchanged. The new queue item will be sized to the larger of the receiver queue size or items. The selection of the items will wrap from the end around to the beginning of the queue. For example,
q1 = .circularqueue~of("Fred", "Mike", "David")
q2 = q1~section(2)        -- effectively rotates the queue

do name over a
   say name  -- displays "Mike", "David", and "Fred"
end
returns a new queue of three items, starting with the second item, effectively rotating the order of the contained items.