All formatting should be fixed, and one of the efficiency issues - it no longer duplicates the iterator.  However, I thought of a new test to add - running it on partitions with fewer elements than the window size - which it fails at the moment.  The solution to that will be much easier once I fix the other efficiency issue - bringing the inter-partition pieces onto the master for processing - so that will be fixed as I address that last issue.
Get rid of groupByKey(1) in sliding, and bring the calculation of inter-split sets completely onto the driver node.  On the driver node, we can handle the fact that some partitions may have fewer elements than the size of the sliding window, or may even be empty.  Add test cases for both potential issues.