coalesceList

fun <I : IntervalLike<I>> coalesceList(list: List<I>, shouldCoalesce: I.(I) -> Boolean): List<I>

Flattens overlapping segments into non-overlapping segments with unequal consecutive values.

Input condition: segments must be sorted such that between each pair of consecutive elements, one of the following is true:

  • if the values are unequal, the start and end times (including inclusivity) must be strictly increasing

  • if the values are equal, the start time must be non-decreasing.

This input condition is not checked, and violating it is undefined behavior.

Empty intervals are removed, and their values are not considered for the purposes of the sorted input condition.