Add grouped_slice helper and use it.

issue3516
review10301002