Add type variances for doOnEach actions.

This fixes the use of contravariant actions (issue #532)