Lesson 8 of 15
Higher-Order Functions
Higher-Order Functions
Functions in F# are first-class values — you can pass them as arguments:
let apply f x = f x
let double x = x * 2
printfn $"{apply double 5}" // 10
Anonymous functions use fun:
let result = apply (fun x -> x + 10) 5
printfn $"{result}" // 15
List.map applies a function to every element:
let nums = [1; 2; 3; 4; 5]
let doubled = List.map (fun x -> x * 2) nums
// [2; 4; 6; 8; 10]
Your Task
Write a function sumDoubled that takes a list of integers and returns the sum of each element doubled. Use List.map and List.sum.
JS Transpiler loading...
Loading...
Click "Run" to execute your code.