export {min, max, fold} function min(uint a, uint b) returns (uint) { return a < b ? a : b; } function max(uint a, uint b) returns (uint) { return a > b ? a : b; } // Problems here: // - we need another definition for calldata or storage arrays. We could also say that the // data location needs to be part of the templat etype, but then we cannot just // replace `T`, since memory has to go after the `[]`. // - the state mutability of the function type cannot be specified. function fold[T, V, F]( T[] memory _array, V memory initial, function(V memory, T memory) returns (V memory) f ) returns (V memory result) { result = initial; for (uint i = 0; i < _array.length; i++) result = f(result, _array[i]); }