objeck / objeck-lang

Objeck is a modern object-oriented programming language with functional features tailored for machine learning. It emphasizes expression, simplicity, portability, and scalability. The programming environment consists of a compiler, virtual machine, REPL shell, and command line debugger with IDE plugins.
https://objeck.org
Other
154 stars 11 forks source link

[discussion] Add `->ToArray()` to Collections #288

Closed ghost closed 1 year ago

ghost commented 1 year ago

Currently, only Vector has ->ToArray() method.

objeck commented 1 year ago

Most collection classes allow one to access values (and keys) via vectors. The Vector class has a ToArray() method. Could you tell me if you're referring to a specific collection class? For example, the List class does not provide vector access by design.

ghost commented 1 year ago

I get the idea from Java. Almost all of the Collections I know on Java have a .toArray() method.

objeck commented 1 year ago

Ok, I got it. Not sure how useful that is for classes like List, Queue, Stack, Cache, etc. I will tag this as an enhancement.

ghost commented 1 year ago

Ok, I got it. Not sure how useful that is for classes like List, Queue, Stack, Cache, etc. I will tag this as an enhancement.

You could consult the Java document by Oracle. It seems almost all Collections have a .toArray() method. For example: https://docs.oracle.com/javase/8/docs/api/java/util/Stack.html (scroll down and you will see toArray listed on methods). Btw, I don't see Java has any Cache class as part of their Collections.

objeck commented 1 year ago

Added ToArray() method to the List, Queue, and Stack classes. All other classes allow access to key/value vectors. Vectors can be converted to arrays also using their ToArray() method.