Skip to content
This repository was archived by the owner on Oct 22, 2024. It is now read-only.

Commit caf6802

Browse files
authored
Tweak docs for split extensions (#256)
- Fix the doc for `splitAfter` to use "after" instead of "before". - Expand the details for the "after" methods with a more explicit mention of how the element that satisfies the predicate is the last value in it's sublist. - Use the same input for the example in `splitBefore` as `splitAFter` so that the distinction is more clear. - Use "remaining elements" instead of "final elements".
1 parent efd709f commit caf6802

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## 1.17.1-dev
22

33
* Require Dart 2.18
4+
* Improve docs for `splitAfter` and `splitBefore`.
45

56
## 1.17.0
67

lib/src/iterable_extensions.dart

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -415,27 +415,28 @@ extension IterableExtension<T> on Iterable<T> {
415415
/// Splits the elements into chunks before some elements.
416416
///
417417
/// Each element except the first is checked using [test]
418-
/// for whether it should start a new chunk.
418+
/// for whether it should be the first element in a new chunk.
419419
/// If so, the elements since the previous chunk-starting element
420420
/// are emitted as a list.
421-
/// Any final elements are emitted at the end.
421+
/// Any remaining elements are emitted at the end.
422422
///
423423
/// Example:
424424
/// Example:
425425
/// ```dart
426-
/// var parts = [1, 2, 3, 4, 5, 6, 7, 8, 9].split(isPrime);
427-
/// print(parts); // ([1], [2], [3, 4], [5, 6], [7, 8, 9])
426+
/// var parts = [1, 0, 2, 1, 5, 7, 6, 8, 9].splitBefore(isPrime);
427+
/// print(parts); // ([1, 0], [2, 1], [5], [7, 6, 8, 9])
428428
/// ```
429429
Iterable<List<T>> splitBefore(bool Function(T element) test) =>
430430
splitBeforeIndexed((_, element) => test(element));
431431

432-
/// Splits the elements into chunks before some elements.
432+
/// Splits the elements into chunks after some elements.
433433
///
434-
/// Each element is checked using [test] for whether it should start a new
435-
/// chunk.
436-
/// If so, the elements since the previous chunk-starting element
434+
/// Each element is checked using [test] for whether it should end a chunk.
435+
/// If so, the elements following the previous chunk-ending element,
436+
/// including the element that satisfied [test],
437437
/// are emitted as a list.
438-
/// Any final elements are emitted at the end.
438+
/// Any remaining elements are emitted at the end,
439+
/// whether the last element should be split after or not.
439440
///
440441
/// Example:
441442
/// ```dart
@@ -451,7 +452,7 @@ extension IterableExtension<T> on Iterable<T> {
451452
/// for whether a chunk should end between them.
452453
/// If so, the elements since the previous chunk-splitting elements
453454
/// are emitted as a list.
454-
/// Any final elements are emitted at the end.
455+
/// Any remaining elements are emitted at the end.
455456
///
456457
/// Example:
457458
/// ```dart
@@ -467,7 +468,7 @@ extension IterableExtension<T> on Iterable<T> {
467468
/// for whether it should start a new chunk.
468469
/// If so, the elements since the previous chunk-starting element
469470
/// are emitted as a list.
470-
/// Any final elements are emitted at the end.
471+
/// Any remaining elements are emitted at the end.
471472
///
472473
/// Example:
473474
/// ```dart
@@ -498,9 +499,10 @@ extension IterableExtension<T> on Iterable<T> {
498499
///
499500
/// Each element and index is checked using [test]
500501
/// for whether it should end the current chunk.
501-
/// If so, the elements since the previous chunk-ending element
502+
/// If so, the elements since the previous chunk-ending element,
503+
/// includeing the elemenent that satisfied [test],
502504
/// are emitted as a list.
503-
/// Any final elements are emitted at the end, whether the last
505+
/// Any remaining elements are emitted at the end, whether the last
504506
/// element should be split after or not.
505507
///
506508
/// Example:
@@ -529,7 +531,7 @@ extension IterableExtension<T> on Iterable<T> {
529531
/// checked using [test] for whether a chunk should end between them.
530532
/// If so, the elements since the previous chunk-splitting elements
531533
/// are emitted as a list.
532-
/// Any final elements are emitted at the end.
534+
/// Any remaining elements are emitted at the end.
533535
///
534536
/// Example:
535537
/// ```dart

0 commit comments

Comments
 (0)