// Passing a Function Object to Another Function
// ==================================================
// Title: Higher-Order Function
// ==================================================
//
// A higher-order function accepts another function
// as an argument.
//
type Operation = (a: number, b: number) => number;
function calculate(
a: number,
b: number,
operation: Operation
): number {
return operation(a, b);
}
const add: Operation = (x, y) => x + y;
const multiply: Operation = (x, y) => x * y;
console.log(calculate(10, 5, add));
console.log(calculate(10, 5, multiply));
/*
run:
15
50
*/