Is there some existing core function that can be used to partition a sorted list so that [1 2 3 7 8 14 15 16 17 20 21 22] becomes [[1 2 3] [7 8] [14 15 16 17] [20 21 22]]?
I can think of how to do with with a loop (start a new list each time the difference between current and previous is greater than 1), but I suspect there's a functional way of expressing this.
For context, this toy problem is a simplified version of a data cleaning exercise where I'm trying to identify where a sensor's data collection was interrupted (e.g. power outage) by examining the difference between the timestamps of the data. I can see functions like split-with, but I don't think the predicate provided to those functions can be provided with the value of the previous item in the sequence in order to make the comparison between items in the sequence.
Thanks for your consideration :)