how to stream a collection backwards without copies?
问题 I would like to know how to stream a collection backwards without copies in Pharo/Squeak. For example, to stream #(1 2 3) so stream next returns 3 , then 2 , then 1 . I know I could just use collection reversed readStream , but reversed copies. 回答1: You could use a Generator: | coll stream | coll := #(1 2 3). stream := Generator on: [:g | coll reverseDo: [:ea | g yield: ea]]. stream next Generators let you wrap a streaming interface around any piece of code, basically. 回答2: Create the