Comments (9)
I assume the put() call was modeled after the Java Map put() function, which returns the previous value, not the map itself. The current code returns void, but it might be confusing to return this when no other Map in Java does that (including TreeMap). https://docs.oracle.com/javase/8/docs/api/java/util/Map.html#put-K-V-
Is there a reason you want to chain here? You can always put code into a static {} block.
from allwpilib.
We could implement this function from the standard library:
https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/Map.html#ofEntries(java.util.Map.Entry...)
I strongly suggest we don't deviate from stdlib conventions, because it's intended to act like a stdlib type.
from allwpilib.
An API shape like Java's existing Map.of
but accepting a variadic double
array would be preferred.
InterpolatingDoubleTreeMap interpolationMap =
InterpolatingDoubleTreeMap.of(
2.90, 62,
2.52, 55,
2.25, 50,
3.59, 63,
3.04, 56
);
from allwpilib.
no new allocation just return this
from allwpilib.
What if instead of put()
it was named addEntry()
, withEntry()
, or something else which doesn't have an existing meaning/convention like put()
?
from allwpilib.
if this is decided to be done I have no prob implementing it.
from allwpilib.
I think so long as you don't have to allocate a new object each time this is a fine feature to add
from allwpilib.
I can see why some people would prefer a variadic double array but I can say for myself that I prefer chaining the .put() method for a clear separation between each pair.
so how about adding both?
from allwpilib.
the reason is ease of use and readability.
I prefer the lower example it makes it easier and faster to add multiple values one after the other and keeps a clear separation between the added values, unlike a variadic double array.
a variadic double array would also be good enough for me but I think chaining would be easier, especially for beginners.
static {
shooterAngleInterpolation.put(2.9, 62.0);
shooterAngleInterpolation.put(2.52, 55.0);
shooterAngleInterpolation.put(2.15, 50.0);
shooterAngleInterpolation.put(3.59, 63.0);
shooterAngleInterpolation.put(3.04, 56.0);
}
shooterAngleInterpolation.put(2.9, 62.0)
.put(2.52, 55.0)
.put(2.15, 50.0)
.put(3.59, 63.0)
.put(3.04, 56.0);}
from allwpilib.
Related Issues (20)
- roboRIO Team Number Setter crashes while refreshing status
- Segfault when destroying AprilTag detector
- Upgrade to PMD 7.1.0 HOT 1
- Remove RuntimeLoader and RuntimeDetector
- C++ command based examples don't all use CommandPtr HOT 3
- Example of LTVUnicycleController with path following
- ElevatorExponentialProfile example HOT 1
- Add usage reporting ID for DataLogManager (and/or DataLog)
- CMake: macOS: glassnt Library Does Not Link HOT 10
- Add abseil-cpp as a 3rd party library HOT 2
- Add Example Command-Based Best-Practices
- Deprecate robotInit() HOT 2
- CommandRobot discussion HOT 1
- DifferentialDrivetrainSimTest doesn't converge (sometimes) because of LTVUnicycleController HOT 1
- Add `Twist2d ChassisSpeeds::ToTwist2d(units::second_t dt) const`
- Use Java StackWalker API instead of custom logic HOT 1
- Refactor default commands to be held by the subsystem (resource) not the scheduler. HOT 1
- `SimHooks.stepTiming()` hangs when called from a callback registered with `SimDeviceSim.registerValueChangedCallback()` if another `SimDeviceSim` has been created HOT 2
- Make usage of `Set` and `...` syntax more consistent HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from allwpilib.