This one, thanks to glguy: 0 999 3 0 999 5 union sum And this one, able to take arbitrary number of ranges, thanks to Slava / glguy / hotaru2k3: { 3 5 } [ [ 999 ] keep ] gather sum