let truncate k = keep_whilei (fun j _ -> j < k)