fun <T> consolidate(ranges: Iterable<ClosedRange<T>>): List<ClosedRange<T>> where T: Comparable<T>
{
    return ranges
        .sortedWith(compareBy({ it.start }, { it.endInclusive }))
        .asReversed()
        .fold(mutableListOf<ClosedRange<T>>()) {
            consolidatedRanges, range ->
            if (consolidatedRanges.isEmpty())
            {
                consolidatedRanges.add(range)
            }