I have a list of time-spans (given as Integer-Tuples), e.g.:
timespans = [ (1200, 1210)
, (1202, 1209)
, (1505, 1900)
, (1300, 1500)
, (1400, 1430)
]
I want to find an elegant Haskell solution to determine time gaps which are not covered by the timespans in the list.
First I would sort the spans by their starting time. Then you can merge overlapping spans pretty easily. Once you have that you can find the gaps by just iterating over the merged spans in pairs (by zipping it with its tail). The gap will be the span from the end time of the first item of the pair to the starting time of the second item.
In code this would look like this:
Usage: