Hi, I am exploring filter() and anonymous functions. I'd like to e.g. filter on a collection of matrices removing matrices which have less rows than a certain critical threshold.
function play1(X, nobsTreshold) filter(x->size(x,1)>nobsTreshold, X) end function play2(X, nobsTreshold) g(x) = size(x, 1) > nobsTreshold filter(g, X) end a = [ rand(i, 3) for i in 1:10 ] play1(a, 7) play2(a, 7) Both functions works correctly. I'd like to ask the following: 1) Is filter an effictient way for doing this ? I assume yes (optionally using an inplace version filter!() may be advantageous). 2) It was surprising to me to see that "nobsTreshold" is visible to the anonymous function in play1() and also to g() in function play2(). I thought that in general function can see only its input parameters. Anyway, it is extremely useful that e.g. in line g(x) = size(x, 1) > nobsTreshold; g(x) sees nobsTreshold Thanks, Jan
