Create a sequence from a spread (inside a vl patch)

tl;dr : how to convert spreads to sequences?

hi, i still have a lot of questions when trying to handle the different data types within vl.

since there are only a few girlpower patches and the gray-book lacks a lot of screenshots, most of the time i cant help myself.
so , please forgive stupid questions:

as far as i know, if i want to apply a for-each-region to a (vvvv)-spread, then i need this (vvvv)-spread as a sequence.
if i input the (vvvv)-spread as a sequence(e.g. via the new type-browser), like sequence, i receive this (vvvv)-spread as a sequence and can apply this for each region, cool!
but
what if i have a vl-spread and want to apply a for-each region to it?
how can i “convert” this (vl)spread to a sequence?
i couldnt find any nodes which have a spread as input and a seuence as output?

i guess this has some reasons, can someone please point me to the explanation in the gray-book? or give any hints how to convert?

thank you.

You can’t find such a node because there’s simply no need to convert a spread to a sequence as the spread is a sequence already. We say the type spread is a subtype of the type sequence. There’re many other types which are also a sequence, like a dictionary, a set, a tree (all in memory) or more sophisticated ones which compute their values only when iterated by something like a loop - take those GroupBy, Where, ProjectMany nodes for example.

In any case, the question is why did you even run into this problem? Were you unable to connect a spread to an input of a loop? If so it would be interesting to see a patch showing the issue.

bit offtopic:
why do we need sequences AND spreads anyway? can’t we get rid of one of them? is it better/faster to use sequences over spreads?

@elias
problem was: i didnt tried to connect a source with a sink
my fault, but you know, vl seems so strict with connectivity of types; that i just thought: “ok, same type connects, different type doesnt”

your exlpaination of
=subtype of
helps a lot(where is this info in the gray-book?)

@sebl:
good question

the topic “data structures and algorithms” is very huge, there is always the best data structure for a specific algorithm and there is no data structure which behaves good/efficient in all cases. so in theory your question should rather be, guys how did you manage to break everything down to Spread and Sequence…? :)

Sequence is the most simple collection type, its only ability is to iterate thru a number of elements. it cannot tell you how long it is nor give you element number X directly (random access) and so on. It is actually the IEnumerable interface of C#. The simplicity of it is a huge advantage since every collection and even algorithms can implement this interface and appear as a sequence, as elias explained. there are hundreds of algorithms which work with this interface and we thought its a good idea to have it in the language…

the type Spread is our own concrete collection type which resembles the convenience of the vvvv spread behavior and we also thought that this is a good idea. it has only the methods we write for it, but since its a Sequence (and implements some other interfaces) it can be used in all algorithms written for IEnumerable. it can tell you how long it is and has random element access and other methods which are efficient, but other methods like changing the value of an element or removing random elements are not so efficient, in fact every change of the data in a Spread creates a new copy of the data to ensure the immutability which is important for a dataflow language like VL. So its a trade-off between convenience, performance and compatibility. Similar to List in C#, the go-to collection type which works in most cases.

a rule of thumb when writing nodes/methods/algorithms is to expect as simple as possible data types at the input and output as specific as possible data types. this enables you to put in many different types but allows you to call specialized methods on the output data. and this is how we modeled loops and other parts of the library.

of course this text should be in the gray book and it will be after a review…

ok, i assumed smth. like that already. and it’s very cool to have that “low level” access. maybe the name ‘sequence’ is a bit unfamiliar - though i think it’s a good and descriptive name.

i guess it’s just a bit strange for vvvv users, because we didn’t had the ability to think with such things until now.

thanks for the detailed explanation!