# advent-of-code

Ozioma Ogbe

12/05/2023, 11:30 AM
Does it make sense to have stdlib functions to check if ranges overlap or to merge ranges.

Neil Banman

12/05/2023, 3:33 PM
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.

Michael de Kaste

12/05/2023, 6:06 PM
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

Dan Fingal-Surma

12/05/2023, 10:00 PM
Guava has RangeSet for this

Michael de Kaste

12/06/2023, 6:24 AM
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[] //practitioner, patient1, patient2
I haven't updated my 'public' one in a while but the gist is here: