[squeak-dev] Xtreams question - OC of chars to String

Chris Cunnington smalltalktelevision at gmail.com
Sun Dec 30 16:27:12 UTC 2012


On 2012-12-30 1:01 AM, mkobetic at gmail.com wrote:
> "Chris Cunnington"<smalltalktelevision at gmail.com> wrote:
>> I don't know. The situation is more like:
>>
>>       oc := #($a $b $c).
>>       oc := oc asOrderedCollection.
>>       oc reading read: 3   an OrderedCollection($a $b $c)
>>
>>
>> The terminal is the OC. But it returns an OC and I want a string from
>> the chars. I've been looking at the transforms page of the Xtreams docs
>> and that seems more about changing the encoding. I think my problem
>> wasn't really about Xtreams.
> Hm, I have to admit that collection streams should perhaps support overriding their contentsSpecies. As it is they assume it should be the same as that of their underlying collection. One might argue that terminal streams should stick to their primary purpose of accessing terminals rather than trying to support some types of conversions as well. But there already is a precedent of sorts in the external streams, so it's not entirely solid argument either.
> Barring that, you could write instead of reading, which would allow you to control the type of the terminal collection.
>
> 	String new writing write: 'abcdefg' asOrderedCollection; close; terminal
That's pretty nifty. Perhaps I was reading when I should have been writing.
>
> The reading equivalent would be using the longer version of read where you pass in the target collection but you're then forced to handle the collection size explicitly which seems less elegant:
>
> 	oc :=  'abcdefg' asOrderedCollection.
> 	string := String new: oc size.
> 	oc reading read: oc size into: string.
>
> It feels sort of like doing the job of the write stream above by hand. You could also use an identity transform that allows setting the contents species:
>
> 	('abcdefg' asOrderedCollection reading collecting: [ :c | c ]) contentsSpecies: String; rest
Stacks and transforms came to mind with Xtreams: sending one kind of 
content into another stream while changing the elements. This was I was 
trying to reach for, but you first example looks the best.

Thanks,
Chris
>
> But that again feels like more trouble than it's worth. I think that's about all that Xtreams have to offer here.
>
> HTH,
>
> Martin
>
>



More information about the Squeak-dev mailing list