A mutating function can modify an input object instead of returning every result in a new object. Julia marks many such functions with !, as in push! and map!. section 4.7
Use mutating functions when:
- map! writes transformed values directly into a preallocated destination array, reducing repeated allocations. section 4.7
- push! adds an element to an existing array and potentially alters the array passed as its input. section 4.7
- Prefer a single combined transformation when readability and data-flow analysis matter more than in-place updates. section 4.7
Transform values in place
Preallocate storage, then reuse it for successive mappings: result = zeros(Float64, length(0:15:90)); map!(deg2rad, result, 0:15:90); map!(sin, result, result). The final call uses the same array as input and output. section 4.7
result = zeros(Float64, length(0:15:90)) #1 map!(deg2rad, result, 0:15:90) #2 map!(sin, result, result) #2
Shows the compact Julia pattern for allocating a destination and applying map! transformations in place. section 4.7
