static flatten method for associative terms.