class Extensions {
inline static public function findMin<T>(a:Array<T>, f:T->Float) {
var minVal = Math.POSITIVE_INFINITY;
var minItem = null;
for (item in a) {
var v = f(item);
if (v < minVal) {
minVal = v;
minItem = item;
}
}
return {item: minItem, val: minVal};
}
inline static public function findMaxValue<T>(a:Array<T>, f:T->Float):Float {
return -findMin(a, i -> -f(i)).val;
}
}
class Test {
static function main() {
var arr = [5, 4, 65, 8];
trace(Extensions.findMaxValue(arr, e -> e * 2));
}
}
*The `e -> e 2` closure is not inlined**, even though it's only used in inline functions
let arr = [5,4,65,8];
let f = function(e) {
return e * 2;
};
let minVal = Infinity;
let _g = 0;
while(_g < arr.length) {
let v = -f(arr[_g++]);
if(v < minVal) {
minVal = v;
}
}
console.log("Test.hx:23:",-minVal);
In this situation
*The `e -> e 2` closure is not inlined**, even though it's only used in inline functions
On Try Haxe, the JS Source still shows