interface Predicate<T> { (x: T): boolean }
function keepIf<T>(arr: T[], pred: Predicate<T>): T[] {
return arr.filter(pred)
}Passing a typed function interface as an argument enforces the callback signature at compile time.
Challenge: Implement applyCallback<T, U>(value, callback) that applies callback to value and returns the result.
applyCallback(5, x => x * 2) // β 10
applyCallback('hello', s => s.length) // β 5