implement filter in terms of fold