using collect on a ReadStream

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

using collect on a ReadStream

NorbertHartl
Hi,

I get a ReadStream from some part of a program which is
created this way

stream := (ReadStream on: #( #(#a #b) #(#b #c)))

I like to use collect: on that stream:

stream collect: [:each| 'k',each first]

Is there a possibility to specify the resulting collection
produced by collect. The problem here is the species
call with an add: call afterwards which is not appropriate
(the debugger said :) )

thanks,

Norbert

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: using collect on a ReadStream

onierstrasz

Hi Norbert,

Streams don't support the collection protocols.  You can convert a  
stream to a collection by sending #contents to the stream:

stream := (ReadStream on: #( #(#a #b) #(#b #c))).
stream contents collect: [:each| 'k',each first] --> #('ka' 'kb')

Is that what you want?

Cheers, Oscar

On Oct 30, 2007, at 2:00, Norbert Hartl wrote:

> Hi,
>
> I get a ReadStream from some part of a program which is
> created this way
>
> stream := (ReadStream on: #( #(#a #b) #(#b #c)))
>
> I like to use collect: on that stream:
>
> stream collect: [:each| 'k',each first]
>
> Is there a possibility to specify the resulting collection
> produced by collect. The problem here is the species
> call with an add: call afterwards which is not appropriate
> (the debugger said :) )
>
> thanks,
>
> Norbert
>
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://lists.squeakfoundation.org/mailman/listinfo/beginners

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: using collect on a ReadStream

NorbertHartl

On Tue, 2007-10-30 at 08:03 +0100, Oscar Nierstrasz wrote:

> Hi Norbert,
>
> Streams don't support the collection protocols.  You can convert a  
> stream to a collection by sending #contents to the stream:
>
> stream := (ReadStream on: #( #(#a #b) #(#b #c))).
> stream contents collect: [:each| 'k',each first] --> #('ka' 'kb')
>
> Is that what you want?
>
Sure, it works :) What I do not understand is that a lot of the
collection protocol is in ReadStream. It has detect: select:
collect: includes: ... What is it for?

thanks,

Norbert

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: using collect on a ReadStream

onierstrasz

Strange.  I do not see these methods supported by ReadStream in my  
image.

I only see 13 implementors of #collect:

What does your implementation of ReadStream>>collect: say?

Oscar

On Oct 30, 2007, at 8:20, Norbert Hartl wrote:

>
> On Tue, 2007-10-30 at 08:03 +0100, Oscar Nierstrasz wrote:
>> Hi Norbert,
>>
>> Streams don't support the collection protocols.  You can convert a
>> stream to a collection by sending #contents to the stream:
>>
>> stream := (ReadStream on: #( #(#a #b) #(#b #c))).
>> stream contents collect: [:each| 'k',each first] --> #('ka' 'kb')
>>
>> Is that what you want?
>>
> Sure, it works :) What I do not understand is that a lot of the
> collection protocol is in ReadStream. It has detect: select:
> collect: includes: ... What is it for?
>
> thanks,
>
> Norbert
>
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://lists.squeakfoundation.org/mailman/listinfo/beginners

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: using collect on a ReadStream

NorbertHartl

On Tue, 2007-10-30 at 08:27 +0100, Oscar Nierstrasz wrote:
> Strange.  I do not see these methods supported by ReadStream in my  
> image.
>
> I only see 13 implementors of #collect:
>
> What does your implementation of ReadStream>>collect: say?
>
Oh, I'm sorry. The methods in ReadStream are added by Glorp. So
I take another list for asking :)

FYI the implementation is

ReadStream>>collect: aBlock
        | newStream |
        newStream := AddingWriteStream on: collection species new.
        [self atEnd] whileFalse: [newStream nextPut: (aBlock value: self
next)].
        ^newStream contents

Norbert

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners