Generalize Pipelines to Workflows.

I’ve tried to make this PR as small as possible – containing only the changes necessary for the Workflow conversion. It’s still pretty big.
The two commented cases will be uncommented when I make the PR with tests for arbitrary `$where` clauses. So, the comments are not ideal, but should be quite short-lived.