-
Notifications
You must be signed in to change notification settings - Fork 323
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consolidate Vector and Array methods #6218
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code and tests look good.
Unless there is a reason, I think we need to add doc comments to the methods on the Array. It's not a PRIVATE type. If it is to be private - OK, but then we should probably mark all the methods at PRIVATE
. In general I think that in our libraries we should not have methods that are neither marked PRIVATE
nor have at least one sentence of documentation.
engine/runtime/src/main/java/org/enso/interpreter/runtime/data/ArraySlice.java
Outdated
Show resolved
Hide resolved
engine/runtime/src/main/java/org/enso/interpreter/runtime/data/Vector.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ready for your reviews @hubertp, @4e6, @radeusgd and @jdunkerley.
@@ -225,7 +225,7 @@ type Vector a | |||
|
|||
## Combines all the elements of the vector, by iteratively applying the | |||
passed function with the next element of the vector. After each step the | |||
value is stored resulting in a new Vector of the same size as self. | |||
value is stored resulting in a new vector of the same size as self. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whenever there is vector
in lowercase, it is replaced by array
when comparing the documentation in the Array
type.
@@ -499,12 +499,12 @@ type Vector a | |||
map self function = | |||
Vector.new self.length i-> function (self.at i) | |||
|
|||
## Applies a function to each element of the vector, returning the vector | |||
## Applies a function to each element of the vector, returning the `Vector` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sometimes we don't want to replace the Vector
word in the Array
documentation. I am then writing the Vector
with capital first letter and quoting it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good.
I'd appreciate a short note on ArraySlice.createOrNull
explaining what is the meaning of it returning null (we have discsused this here, but no on reading the code will know to look around this PR discussion for details, and it would make reading it much easier).
var head = arrayFns.filter((av) -> av instanceof IR$Function$Binding ab && ab.name().name().equals(b.name().name())).head(); | ||
var ad = documentation.get(head); | ||
assertNotNull("No documentation for Array." + name, ad); | ||
var exp = d.doc() | ||
.replace("]", "].to_array") | ||
.replace("a vector", "an array") | ||
.replace("vector", "array"); | ||
assertEquals("Bad documentation for Array." + name, exp, ad.doc()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wow 😀 neat
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good - I do wonder if the return type of the methods should be Array instead of Vector.
Usually not. Usually the return type should be |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Engine part looks good 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about Array_Proxy
and ArrayOverBuffer
?
Plus minor nits in type signatures.
btw I'm guessing it is intentional that Array
methods often return Vector
? It feels a bit weird that one operates on the former and always gets the latter.
Concatenate two single-element arrays. | ||
|
||
[1].to_array + [2].to_array | ||
+ : Vector Any -> Vector Any |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The type should be an Array?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The in type can be either Vector
or Array
. The output type is Vector
.
of both elements. | ||
|
||
[1, 2, 3].to_array.zip [4, 5, 6].to_array == [[1, 4].to_array, [2, 5].to_array, [3, 6].to_array].to_array | ||
zip : Vector Any -> (Any -> Any -> Any) -> Vector Any |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
zip : Vector Any -> (Any -> Any -> Any) -> Vector Any | |
zip : Array Any -> (Any -> Any -> Any) -> Vector Any |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again. The proper input type is either Vector
or Array
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, so if I was a real PITA I would say that this should be (Array Any | Vector Any)
:)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moreover that applies to the whole codebase. Everywhere Vector
is used, Array
can be used as well!
Rather than modifying all the type signatures, let's hope further consolidation renders these two types obsolete and allows them to be merged into one. Because Array
is basically Vector in Input
- e.g. Vector
that can change due to changes made elsewhere and may need to be read (Input
ed) again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That sounds like a good idea for the future.
Alternatively, I'd keep the Vector/Array distinction but make the type signatures rely on some interface/typeclass - like IndexedSequence
- and then both Array and Vector would 'implement' this interface/typeclass, so they could be used where it is expected.
I had to fix one test because of
The (philosophical) difference between |
Pull Request Description
Fixes #5011 by making sure the same methods that are on
Vector
are also available onArray
.Important Notes
Checklist
Please ensure that the following checklist has been satisfied before submitting the PR:
Java,