You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Let custom iterators return multiple values. Since there are no tuples in V custom iterators could be used to handle data that would otherwise be in a tuple.
Use Case
Lets say we have 2 arrays with a different datatype and we want to iterate over those 2 arrays simultaneously.
Right now this could be done by creating a for loop and keeping track of the index, but this code has to be written every time
and is not reusable.
error: iterator method `next()` must not return multiple values
Itertools
I noticed that VSL has some extra iteration tools like cycle, but it is only for f64 and I think a small iterators utility module in the standard library would be good to have.
V full version: V 0.3.3 4e498b4.e738d67
OS: linux, Kali GNU/Linux Rolling (WSL 2)
Processor: 24 cpus, 64bit, little endian, 12th Gen Intel(R) Core(TM) i9-12900K
This discussion was converted from issue #18082 on June 27, 2023 10:01.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Describe the feature
Let custom iterators return multiple values. Since there are no tuples in V custom iterators could be used to handle data that would otherwise be in a tuple.
Use Case
Lets say we have 2 arrays with a different datatype and we want to iterate over those 2 arrays simultaneously.
Right now this could be done by creating a for loop and keeping track of the index, but this code has to be written every time
and is not reusable.
Or
The second example is much better but it is not better than with a custom iterator in my opinion as it involves a callback function.
It would be nice to have a generic function for this like pythons
zip
function. An implementation forzip
would look something like this:At this moment the code above generates an error
Itertools
I noticed that VSL has some extra iteration tools like
cycle
, but it is only forf64
and I think a small iterators utility module in the standard library would be good to have.Proposed Solution
Let iterators return multiple values.
Other Information
No response
Acknowledgements
Version used
V 0.3.3 4e498b4.e738d67
Environment details (OS name and version, etc.)
V full version: V 0.3.3 4e498b4.e738d67
OS: linux, Kali GNU/Linux Rolling (WSL 2)
Processor: 24 cpus, 64bit, little endian, 12th Gen Intel(R) Core(TM) i9-12900K
getwd: /home/casper/code/v/issues
vexe: /opt/v/v
vexe mtime: 2023-04-29 14:35:19
vroot: OK, value: /opt/v
VMODULES: OK, value: /home/casper/.vmodules
VTMP: OK, value: /tmp/v_1000
Git version: git version 2.39.2
Git vroot status: weekly.2023.15-82-ge738d671
.git/config present: true
CC version: cc (Debian 12.2.0-14) 12.2.0
thirdparty/tcc status: thirdparty-linux-amd64 12f392c3
Beta Was this translation helpful? Give feedback.
All reactions