implement filter using a right fold