You can implement this pretty easily with Seq.pairwise
and Seq.map
:
let idleTimes (startStopTimes : seq<DateTime * DateTime>) =
startStopTimes
|> Seq.pairwise
|> Seq.map (fun (_, stop) (start, _) ->
stop, start)
As for the more general question of executing on sequences with different lag periods, you could implement that by using Seq.skip
and Seq.zip
to produce a combined sequence with whatever lag period you require.