Replace Vec#of with VecFactory#ofObjectVec
See original GitHub issueFirst of all: Thank you very much for addressing #546 as part of release 5.2.0.
My code previously looked like:
return Vec.of(fitnesses.stream().toArray(Fitness[]::new));
Now I would like to use the aforementioned new feature with something like:
private final VecFactory<Fitness[]> vecFactory = VecFactory.ofObjectVec(
Comparator.naturalOrder(),
(u, v, i) -> u[i].compareTo(v[i]),
Optimize.MAXIMUM, Optimize.MAXIMUM, Optimize.MINIMUM);
// ...
return vecFactory.newVec(fitnesses.stream().toArray(Fitness[]::new));
However, I’m unsure about the ElementDistance. I was looking into Vec#of in order to replace it with VecFactory#ofObjectVec, where I saw the following code:
static <C extends Comparable<? super C>>
Vec<C[]> of(final C[] array) {
return of(
array,
(u, v, i) -> clamp(u[i].compareTo(v[i]), -1, 1)
);
}
Naturally I would try to do the same, but Basics#clamp is internal and I wonder what is the proper way to reproduce the Vec#of behavior while providing the new optimization directions.
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Replacing element of a vector of objects - c++ - Stack Overflow
I have an std::vector of objects. How do I replace the element at index i, while ensuring the destructor of the object that...
Read more >Replace value from vector array of object - Microsoft Q&A
Replace value from vector array of object. Hi folks,. here is my sample code as below: #include <iostream>; #include <fstream> ...
Read more >Replace the Elements of a Vector in R Programming
replace () function in R Language is used to replace the values in the specified string vector x with indices given in list...
Read more >Replacing Element in Java Vector - GeeksforGeeks
To replace an element in Java Vector, set() method of java.util.Vector class can be used. The set() method takes two parameters-the indexes ...
Read more >Conditionally replace values in a vector in C++ - Techie Delight
The best option to conditionally replace values in a vector in C++ is using the std::replace_if function. It assigns a new value to...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Makes sense, but I would name it
and probably adding also
I’m not sure about the
VecFactory.ofComparableVec(). In this case, you don’t need a factory, you can create aVecinstance withVec.ofdirectly.Wanted to submit a PR, but haven’t found time for it … so thanks a lot for doing it! 🙏