Does it make sense to have stdlib functions to che...
# advent-of-code
o
Does it make sense to have stdlib functions to check if ranges overlap or to merge ranges.
n
For AoC, it’s not something that comes up very often. Last year there was one problem where an overlap check was useful. That’s the only one I can think of.
m
Tbf, it actually is pretty important to us where we make software for mental healthcare. Knowing what codes are relevant; where an allocation and a funding (excuse the direct translation from dutch healthcare) have overlap. It's pretty common usages here. In fact, we had to write our own 'mini' library for ranges in order to work with them
👍 1
d
Guava has RangeSet for this
m
Yeah, but guava's one is pretty clunky and focussed on java We just wanted to write 'x until y' and let the program decide what that means for openness (null means open-ended). I made a library where you can write something like:
Copy code
val intervalMap = listOfData.groupByInterval(
	keySelector = { it.startDate until it.endDate },
	valueSelector = { it.patient },
	defaultValue = { theAlwaysPresentPractitioner },
)

val presentPeople = intervalMap[LocalDateTime.now()] //practitioner, patient1, patient2
I haven't updated my 'public' one in a while but the gist is here: https://github.com/mdekaste/interval/blob/master/src/main/kotlin/Main.kt