I'm trying to wrap my head aroun the bifunction usage in Hazelcast Jets accumulate processor. First attempt is a simple min comparison, but what I came up with looks so unelegant. Is there a better way to do it?
Vertex min = dag.newVertex("min", accumulate(()
-> new myObject(Type.SOME_ENUM,Double.MAX_VALUE,0L),
(cMin, x) -> (((myObject) x).getValue() < cMin.Value()) ? (myObject) x) : cMin,
(cMin) -> cMin));
Basically I have a class with 3 fields: Type, Value, TimeStamp, and I want to get object with the lowest value.
My supplier is a new object with value at max.double, which looks fine. My finisher just hands through the object which is fine as well.
But the accumulator looks unneccesarily complicated. Is there a way to avoid having to cast x to myObject twice? Or some even more elegant way, to just keep the double value, but still return the object at the end? WITHOUT having to iterate to the whole map to get the object for the min value again?