[back]

Consecutives

Implement the function

val consecutives : int -> 'a list -> 'a list list

so that consecutives len l is the list of all consecutive sublists of l of length min len (List.length l). The behavior of the function is undefined if len is not positive.

Hint. use the functions map2 and List.map.

Examples

let _ = assert (consecutives 2 [1;2;3;4;5] = [[1;2];[2;3];[3;4];[4;5]])
let _ = assert (consecutives 1 [] = [[]])
let _ = assert (consecutives 10 [1;2;3;4;5] = [[1;2;3;4;5]])