Make lastOf use foldlOf' to avoid stack overflows