functional version of intervaltree