turning a collection (interval for example) into a stream
Hi I was looking at how we can turn a collection into a stream. I played with g := Generator on: [ :gen | | current | current := 0. [ gen yield: (current := current + 1) ] repeat ]. g next. and now imagine that we have (1 to: 1000) collect: [:each | {each -1 . each . each + 1}]. I was wondering how we could turn it into a stream (1 to: 1000) asStream collect: [:each | {each -1 . each . each + 1}]. and what would be the asStream method. for index based I can see that next next is something like next ^ self at: (current := current + 1) and collect: could be rewritten to use a generator. Now does anybody play with this already? Does xtream provide a way to do something in the same vein? We can have a stream of blocks. Stef
Hi Stef, I have some experiments I did last year in here http://www.smalltalkhub.com/#!/~Guille/ReactiveExtensions They allow you to do something like you want. It is based on the ideas in https://gist.github.com/staltz/868e7e9bc2a7b8c1f754 http://www.introtorx.com/ These guys model a stream with different transformations (such as select:, collect: flatCollect: and so on...) as a chain of observers where each transformation observes the one before, transforms the result and notifies its observers with the modified value. - The funny side is that with these they can manage polymorphically both collections as streams, and normal streams (that may never end). Also they do nice things with concurrency and retry operations fairly easily. - The odd part is DEBUGGING this. * You may have tons of elements into your collection => Then you may block all incoming events as soon as you debug one. * You have to debug chains of observer/observed pairs, with the boilerplate code that comes to it. Maybe a domain specific debugger would be need for this... Guille Guille -------- Original Message --------
Hi
I was looking at how we can turn a collection into a stream.
I played with
g := Generator on: [ :gen | | current | current := 0. [ gen yield: (current := current + 1) ] repeat ]. g next.
and now imagine that we have
(1 to: 1000) collect: [:each | {each -1 . each . each + 1}].
I was wondering how we could turn it into a stream
(1 to: 1000) asStream collect: [:each | {each -1 . each . each + 1}].
and what would be the asStream method.
for index based I can see that next
next is something like
next
^ self at: (current := current + 1)
and collect: could be rewritten to use a generator.
Now does anybody play with this already?
Does xtream provide a way to do something in the same vein?
We can have a stream of blocks.
Stef
Tx guille I will read it. Le 29/9/16 à 11:47, Guille Polito a écrit :
Hi Stef,
I have some experiments I did last year in here
http://www.smalltalkhub.com/#!/~Guille/ReactiveExtensions
They allow you to do something like you want.
It is based on the ideas in
https://gist.github.com/staltz/868e7e9bc2a7b8c1f754 http://www.introtorx.com/
These guys model a stream with different transformations (such as select:, collect: flatCollect: and so on...) as a chain of observers where each transformation observes the one before, transforms the result and notifies its observers with the modified value.
- The funny side is that with these they can manage polymorphically both collections as streams, and normal streams (that may never end). Also they do nice things with concurrency and retry operations fairly easily. - The odd part is DEBUGGING this. * You may have tons of elements into your collection => Then you may block all incoming events as soon as you debug one. * You have to debug chains of observer/observed pairs, with the boilerplate code that comes to it. Maybe a domain specific debugger would be need for this...
Guille
Guille
-------- Original Message --------
Hi
I was looking at how we can turn a collection into a stream.
I played with
g := Generator on: [ :gen | | current | current := 0. [ gen yield: (current := current + 1) ] repeat ]. g next.
and now imagine that we have
(1 to: 1000) collect: [:each | {each -1 . each . each + 1}].
I was wondering how we could turn it into a stream
(1 to: 1000) asStream collect: [:each | {each -1 . each . each + 1}].
and what would be the asStream method.
for index based I can see that next
next is something like
next
^ self at: (current := current + 1)
and collect: could be rewritten to use a generator.
Now does anybody play with this already?
Does xtream provide a way to do something in the same vein?
We can have a stream of blocks.
Stef
2016-09-29 6:54 GMT+02:00 stepharo <stepharo@free.fr>:
and now imagine that we have
(1 to: 1000) collect: [:each | {each -1 . each . each + 1}].
I was wondering how we could turn it into a stream
(1 to: 1000) asStream collect: [:each | {each -1 . each . each + 1}].
and what would be the asStream method.
for index based I can see that next
next is something like
next
^ self at: (current := current + 1)
and collect: could be rewritten to use a generator.
Now does anybody play with this already?
Does xtream provide a way to do something in the same vein?
Yes. XStream supports it: (1 to: 1000) reading transforming: [:in :out | | each | each := in get. out put: each -1; put: each; put: each + 1]
2016-09-29 12:39 GMT+02:00 Denis Kudriashov <dionisiydk@gmail.com>:
and collect: could be rewritten to use a generator.
Now does anybody play with this already?
Does xtream provide a way to do something in the same vein?
Yes. XStream supports it:
(1 to: 1000) reading transforming: [:in :out | | each | each := in get. out put: each -1; put: each; put: each + 1]
But you probably wants different: (1 to: 1000) reading collecting: [:each | {each -1. each. each + 1} ]
Same with transducers/reducers, except they work by pushing values through the pipeline instead of pulling them. The library I started porting from VW last year had a dual API, one more like the original Clojure transducers, and one more like Xtreams. One nice point of going collectionâstream & filtersâresult is that the final step is explicit, so you can pick what kind of result you build (could be a collection or a single aggregated value). On 29 September 2016 at 12:40, Denis Kudriashov <dionisiydk@gmail.com> wrote:
2016-09-29 12:39 GMT+02:00 Denis Kudriashov <dionisiydk@gmail.com>:
and collect: could be rewritten to use a generator.
Now does anybody play with this already?
Does xtream provide a way to do something in the same vein?
Yes. XStream supports it:
(1 to: 1000) reading transforming: [:in :out | | each | each := in get. out put: each -1; put: each; put: each + 1]
But you probably wants different:
(1 to: 1000) reading collecting: [:each | {each -1. each. each + 1} ]
I would love to see this package and a little documentation on it. Stef Le 29/9/16 à 15:02, Damien Pollet a écrit :
Same with transducers/reducers, except they work by pushing values through the pipeline instead of pulling them. The library I started porting from VW last year had a dual API, one more like the original Clojure transducers, and one more like Xtreams.
One nice point of going collectionâstream & filtersâresult is that the final step is explicit, so you can pick what kind of result you build (could be a collection or a single aggregated value).
On 29 September 2016 at 12:40, Denis Kudriashov <dionisiydk@gmail.com <mailto:dionisiydk@gmail.com>> wrote:
2016-09-29 12:39 GMT+02:00 Denis Kudriashov <dionisiydk@gmail.com <mailto:dionisiydk@gmail.com>>:
and collect: could be rewritten to use a generator.
Now does anybody play with this already?
Does xtream provide a way to do something in the same vein?
Yes. XStream supports it:
(1 to: 1000) reading transforming: [:in :out | | each | each := in get. out put: each -1; put: each; put: each + 1]
But you probably wants different:
(1 to: 1000) reading collecting: [:each | {each -1. each. each + 1} ]
It's in http://smalltalkhub.com/#!/~cdlm/Experiments Not sure if it's Transducers or Reducers. Most probably the latter is the ported code from VW, I recall having success running some examples, but the tests probably will not (I recall trying to rewrite them using BabyMock2 but it's either failed or unfinished). On 29 September 2016 at 16:50, stepharo <stepharo@free.fr> wrote:
I would love to see this package and a little documentation on it.
Stef
Le 29/9/16 à 15:02, Damien Pollet a écrit :
Same with transducers/reducers, except they work by pushing values through the pipeline instead of pulling them. The library I started porting from VW last year had a dual API, one more like the original Clojure transducers, and one more like Xtreams.
One nice point of going collectionâstream & filtersâresult is that the final step is explicit, so you can pick what kind of result you build (could be a collection or a single aggregated value).
On 29 September 2016 at 12:40, Denis Kudriashov <dionisiydk@gmail.com> wrote:
2016-09-29 12:39 GMT+02:00 Denis Kudriashov <dionisiydk@gmail.com>:
and collect: could be rewritten to use a generator.
Now does anybody play with this already?
Does xtream provide a way to do something in the same vein?
Yes. XStream supports it:
(1 to: 1000) reading transforming: [:in :out | | each | each := in get. out put: each -1; put: each; put: each + 1]
But you probably wants different:
(1 to: 1000) reading collecting: [:each | {each -1. each. each + 1} ]
Hi denis
Yes. XStream supports it:
(1 to: 1000) reading transforming: [:in :out | | each | each := in get. out put: each -1; put: each; put: each + 1]
But you probably wants different:
(1 to: 1000) reading collecting: [:each | {each -1. each. each + 1} ]
My point is can we control the next action so that we can take any collection and turn it in a stream. Stef
2016-09-29 16:51 GMT+02:00 stepharo <stepharo@free.fr>:
Hi denis
Yes. XStream supports it:
(1 to: 1000) reading transforming: [:in :out | | each | each := in get. out put: each -1; put: each; put: each + 1]
But you probably wants different:
(1 to: 1000) reading collecting: [:each | {each -1. each. each + 1} ]
My point is can we control the next action so that we can take any collection and turn it in a stream.
Transforming is main approach to do this. And it is quite simple
participants (4)
-
Damien Pollet -
Denis Kudriashov -
Guille Polito -
stepharo