Theory

A higherโ€‘order function (HOF) takes functions as arguments or returns them. Allows us to capture common traversal/computation patterns once and reuse forever.

HOFPattern
๐Ÿšฟ Mapapply a transformation to each element
๐Ÿ” Filterkeep elements satisfying a predicate
๐Ÿ“ Foldrย &ย Foldlreduce a list using an operator
โžก๏ธ Function Combinatorsglue functions together (.) or swap args (flip)

Example โ€“ Refactoring with map

shout   = map toUpper
squares = map (^2)

No explicit recursion needed; clarity & composability improve.

Implementation

map :: (a -> b) -> [a] -> [b]
map f []     = []
map f (x:xs) = f x : map f xs

Compiler optimizations like fusion rewrite chains (map f . map g) into one traversal.