generic functions for immutable functional programming idioms