Could this be in a context menu or view menubar?
You can collapse the subtasks of selected tasks (see gif), but I’m not sure I totally understand what you mean by collapse [parent] tasks or entire lists. Can you share a little more context on the use case?