[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Help-smalltalk] [bug] Fold selector fails on streams
From: |
Roman |
Subject: |
[Help-smalltalk] [bug] Fold selector fails on streams |
Date: |
Sun, 02 Sep 2012 04:28:40 -0700 |
Issue status update for
http://smalltalk.gnu.org/node/655
Post 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] ]
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Help-smalltalk] [bug] Fold selector fails on streams,
Roman <=