Generalized matrix trace Inspiration.
Given (by any means):

A two-argument (or single argument consisting of a two-element list) black box function, f: ℤ+ × ℤ+ → ℤ+ (input and output are 1, 2, 3,…)
A strictly positive integer matrix with at least two rows and two columns

return the matrix's function trace.
What is a function trace?
A normal matrix trace is the sum of the major diagonal (top-left to bottom-right) of a matrix:
[[1,2,3],[4,5,6],[7,8,9]] → [1,5,9] → 1+5+9 → 15
But instead of summing, we want to apply f along the diagonal:
[[1,2,3],[4,5,6],[7,8,9]] → [1,5,9] → f(f(1,5),9) or f(1,f(5,9))
Please state whether you use left-to-right or right-to-left.
The given matrix and all intermediate values will be strictly positive integers within your language's integer domain. The matrix may be non-square.
Examples
f(x,y) = xy, [[1,2,3],[4,5,6],[7,8,9]] → 1×5×9 → 45
f(x,y) = xy, [[1,2,3],[4,5,6],[7,8,9]] →  159 → 1
f(x,y) = x-y, [[4,5,6],[1,2,3]] → 4-2 → 2
f(x,y) = (x+y)⁄2, [[2,3,4],[5,6,7],[8,9,10]] → 5 or 7
f(x,y) = x+2y, [[1,2,3],[4,5,6],[7,8,9]] → 47 or 29
f(x,y) = max(x,y), [[1,2,3],[4,5,6],[7,8,9]] → max(1,5,9) → 9
f(x,y) = 2x, [[1,2,3],[4,5,6],[7,8,9]] → 2 or 4
f(x,y) = lcm(x,y), [[2,2,2],[2,2,3],[2,3,3],[4,4,4]] → lcm(2,2,3) → 6
Reference implementation.
R, 40 30 bytes



function(m,F)Reduce(F,diag(m))


Try it online!

Verify the test cases.

Traverses down the diagonal, so left-to-right in this case. For arithmetic operators, you can use "+" or backticks around the operators (+,*,-,%/%,^,%%)

Pretty straightforward: Reduce is R's equivalent to a fold, and the diagonal of a matrix is those elements a_ij where i==j, i.e., where the row and column indices are the same. diag has the appropriate behavior for non-square matrices.