Created
November 7, 2015 12:43
-
-
Save ekozhura/cb682b577a9f86be1fd8 to your computer and use it in GitHub Desktop.
Stream.collect implementation not only creates a new FuncStream, it mutates an original stream.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
( | |
var a, b; | |
a = Routine.new({ | |
inf.do{ |idx = 1| | |
idx.yield; | |
} | |
}); | |
b = a.collect({|item| item * 2;}); | |
b.nextN(10).postln; // -> [ 0, 2, 4, 6, 8, 10, 12, 14, 16, 18 ] | |
a.nextN(10).postln; // -> [ 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 ] WTF?!? | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I found an old thread where James McCartney explained a reason of why routines could not be copied.
sc-dev: strange stream embedding behaviour.
Another observation:
shallowCopy
worked in my previous example becauseb
was created beforea
was started. OtherwiseshallowCopy
would simply return a reference toa
(at least, it seems so). That also makes sense, considering the quote of James McCartney.