A higher-order function takes a function as an argument, returns a function, or both. In Julia, functions can be passed around like other values: `g = sin` lets you call `g(1.0)`. That makes it possible to write one collection-processing function and choose its behavior by passing in another function. section 4.7 section 15.1
Turn angles into a sine table
`map(deg2rad, 0:15:90)` applies `deg2rad` to each angle in the range and returns an array of radians. To get sine values, use `degsin(deg) = sin(deg2rad(deg))`, then `map(degsin, 0:15:90)`. Combining the conversions in one function avoids creating an intermediate array with a second call to `map`. When an existing output array is needed, `map!` writes into it instead. section 4.7
Listing 4.3 Knock-off version of the built-in map function
function transform(fun, xs)
ys = [] #1
for x in xs
push!(ys, fun(x)) #2
end
ys #3
end
A small version of `map` makes the mechanism visible: accept a function and an iterable, call the function for each element, and collect the results. section 4.7
`filter` uses a function differently. It keeps only values for which a predicate returns `true`. For pizza sales, `filter(islarge, sales)` selects large-pizza records; `map(price, ...)` extracts their prices; and `sum(...)` gives the revenue. Filtering, mapping, and reducing can be combined to answer a question without writing a separate loop for every query. section 4.10 section 4.10.1
Map and reduce in one call
In `sinus(x)`, a locally defined `taylor(i)` calculates one Taylor-series term using `x`. The expression `mapreduce(taylor, +, 0:n)` calculates terms for the range and combines them with addition. Defining `taylor` inside `sinus` gives it access to that call's `x`; the example also connects higher-order functions to closures. section 4.11.1 section 15.0
Higher-order functions are a tool for functional design, not a requirement to avoid every loop. They support reuse by separating an operation such as mapping or filtering from the function supplied to it. The same function-centered approach can also be compared with an object-oriented design for an encryption service. section 15.1 section 15.7













