P16 { public static <T> List<T> dropEveryNth(List<T> list, int n) { if (n == 0) { return list; } return IntStream.range(0, list.size()) .mapToObj(i -> new SimpleEntry<>(list.get(i), i)) .filter(entry -> (entry.getValue() + 1) % n != 0) .map(SimpleEntry::getKey) .collect(Collectors.toList()); }  static List<T> dropEveryNth(List<T> list, int n);  }
@Test public void shouldDropEveryNthElement() throws Exception { List<String> result = P16.dropEveryNth(Arrays.asList("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k"), 3); assertThat(result, hasSize(8)); assertThat(result, contains("a", "b", "d", "e", "g", "h", "j", "k")); }
@Test public void shouldReturnSameListWhenNIsLessThanListSize() throws Exception { List<String> result = P16.dropEveryNth(Arrays.asList("a", "b"), 3); assertThat(result, hasSize(2)); assertThat(result, contains("a", "b")); }
@Test public void shouldReturnSameListWhenNIsZero() throws Exception { List<String> result = P16.dropEveryNth(Arrays.asList("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k"), 0); assertThat(result, hasSize(11)); assertThat(result, contains("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k")); }