Issue status update for
http://smalltalk.gnu.org/node/655Post a follow up:
http://smalltalk.gnu.org/project/comments/add/655 Project: GNU Smalltalk
Version: <none>
Component: Base classes
Category: bug reports
Priority: normal
Assigned to: Unassigned
Reported by: Roman
Updated by: Roman
Status: active
Excuse me for my english.
Streams are Iterable. Class Iterable defines a method fold, which must
be sent to any Stream. But in the current implementation method fold can
be sent only to instances of PositionableStream, because method fold is
based on isEmpty selector. For example, Generator does not provide
isEmpty selector:
st> x:=Generator on: [:g| g yield: 1. g yield: 3 ]
a Generator
st> x fold: [:a :b| a+b]
Object: Generator new "<0x403bc180>" error: did not understand
#isEmpty
My solution is:
fold: aBlock [
|marker acc|
acc:=marker:=Object new.
self do: [:i| acc:=acc==marker ifTrue: [i]
ifFalse: [aBlock value: acc value:
i] ].
acc==marker ifTrue: [ SystemExceptions.EmptyCollection signalOn:
self ]
ifFalse: [^acc] ]
_______________________________________________
help-smalltalk mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-smalltalk