We consider a generalized Hardy operator Tf(x) = phi(x) integral-x/0 p
sifupsilon. For T to be bounded from a weighted Banach function space
(X, upsilon) into another, (Y, w), it is always necessary that the Muc
kenhoupt-type condition B = sup(R>0) parallel-to phichi((R,infinity))
parallel-to Y parallel-to psichi(0,R) parallel-to X' < infinity be sat
isfied. We say that (X, Y) belongs to the category M(T) if this Mucken
houpt condition is also sufficient. We prove a general criterion for c
ompactness of T from X to Y when (X, Y) is-an-element-of M(T) and give
an estimate for the distance of T from the finite rank operators. We
apply the results to Lorentz spaces and characterize pairs of Lorentz
spaces which fall into M(T).