nevalang / neva

🌊 Flow-based programming language with static types and implicit parallelism. Compiles to native code and Go
https://nevalang.org
MIT License
85 stars 7 forks source link

`Zip` component #640

Closed emil14 closed 1 month ago

emil14 commented 1 month ago

Fixed (2 inputs)

type ZipResult<T, Y> {
  first T 
  second Y
}

pub component Zip<T, Y>(first stream<T>, second stream<Y>) (res stream<ZipResult<T, Y>>)

Upsides

Downsides

Variadic (N inputs)

pub component Zip<T>([streams] stream<T>) (res stream<T>)

Upsides

Downsides

A Note On Stream Size

We have to decide how to handle streams of different length (size)

I suggest follow how Python does it - finish when first stream is ended. Elements of other stream(s) are simply immited (TODO check if that's true, is Python really like this?)

Catya3 commented 1 month ago

Seems like Python would take the shorter of the two

>>> x=[1,2,3,4]
>>> y=[1,2,3]
>>> list(zip(x,y))
[(1, 1), (2, 2), (3, 3)]
emil14 commented 1 month ago

Done by @Catya3