kotlin-range-sets / com.github.jonpeterson.kotlin.ranges / RangeSet / retainAll

retainAll

open fun retainAll(elements: Collection<ClosedRange<T>>): Boolean (source)

Removes all values from set except those contained in the specified ranges; intersection set logic.

Examples:

assert(IntRangeSet(listOf(5..21)).apply { retainAll(listOf(7..10, 12..15)) }.toList() == listOf(7..10, 12..15))
assert(IntRangeSet(listOf(5..9, 13..21)).apply { retainAll(listOf(7..15, 18..25)) }.toList() == listOf(7..9, 13..15, 18..21))


Parameters

elements - ranges of values to keep

Return
whether any values were removed