Skip to content

Commit

Permalink
Add isPartitioned.
Browse files Browse the repository at this point in the history
  • Loading branch information
markrogoyski committed Feb 15, 2023
1 parent 920c9b6 commit f9f3688
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 24 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* Summary
* `arePermutations`
* `arePermutationsCoercive`
* `isPartitioned`
* Transform
* `tee`
* `toArray`
Expand All @@ -25,6 +26,7 @@
* Summary Terminal Operations
* `arePermutationsWith`
* `arePermutationsCoerciveWith`
* `isPartitioned`
` Transformation`
* `tee`
### Improvements
Expand Down
86 changes: 62 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,18 +137,19 @@ Quick Reference
| [`toIterator`](#To-Iterator) | Transform iterable to an iterator | `Transform::toIterator($data)` |

#### Summary
| Summary | Description | Code Snippet |
|---------------------------------------------------------|---------------------------------------------------------------------|---------------------------------------------------|
| [`allMatch`](#All-Match) | True if all items are true according to predicate | `Summary::allMatch($data, $predicate)` |
| [`anyMatch`](#Any-Match) | True if any item is true according to predicate | `Summary::anyMatch($data, $predicate)` |
| [`arePermutations`](#Are-Permutations) | True if iterables are permutations of each other | `Summary::arePermutations(...$iterables)` |
| [`arePermutationsCoercive`](#Are-Permutations-Coercive) | True if iterables are permutations of each other with type coercion | `Summary::arePermutationsCoercive(...$iterables)` |
| [`exactlyN`](#Exactly-N) | True if exactly n items are true according to predicate | `Summary::exactlyN($data, $n, $predicate)` |
| [`isSorted`](#Is-Sorted) | True if iterable sorted | `Summary::isSorted($data)` |
| [`isReversed`](#Is-Reversed) | True if iterable reverse sorted | `Summary::isReversed($data)` |
| [`noneMatch`](#None-Match) | True if none of items true according to predicate | `Summary::noneMatch($data, $predicate)` |
| [`same`](#Same) | True if iterables are the same | `Summary::same(...$iterables)` |
| [`sameCount`](#Same-Count) | True if iterables have the same lengths | `Summary::sameCount(...$iterables)` |
| Summary | Description | Code Snippet |
|---------------------------------------------------------|--------------------------------------------------------------------------|---------------------------------------------------|
| [`allMatch`](#All-Match) | True if all items are true according to predicate | `Summary::allMatch($data, $predicate)` |
| [`anyMatch`](#Any-Match) | True if any item is true according to predicate | `Summary::anyMatch($data, $predicate)` |
| [`arePermutations`](#Are-Permutations) | True if iterables are permutations of each other | `Summary::arePermutations(...$iterables)` |
| [`arePermutationsCoercive`](#Are-Permutations-Coercive) | True if iterables are permutations of each other with type coercion | `Summary::arePermutationsCoercive(...$iterables)` |
| [`exactlyN`](#Exactly-N) | True if exactly n items are true according to predicate | `Summary::exactlyN($data, $n, $predicate)` |
| [`isPartitioned`](#Is-Partitioned) | True if partitioned with items true according to predicate before others | `Summary::isPartitioned($data, $predicate)` |
| [`isSorted`](#Is-Sorted) | True if iterable sorted | `Summary::isSorted($data)` |
| [`isReversed`](#Is-Reversed) | True if iterable reverse sorted | `Summary::isReversed($data)` |
| [`noneMatch`](#None-Match) | True if none of items true according to predicate | `Summary::noneMatch($data, $predicate)` |
| [`same`](#Same) | True if iterables are the same | `Summary::same(...$iterables)` |
| [`sameCount`](#Same-Count) | True if iterables have the same lengths | `Summary::sameCount(...$iterables)` |

#### Reduce
| Reducer | Description | Code Snippet |
Expand Down Expand Up @@ -227,18 +228,19 @@ Quick Reference

#### Stream Terminal Operations
##### Summary Terminal Operations
| Terminal Operation | Description | Code Snippet |
|------------------------------------------------------------------|-------------------------------------------------------------------------|--------------------------------------------------------|
| [`allMatch`](#All-Match-1) | Returns true if all items in stream match predicate | `$stream->allMatch($predicate)` |
| [`anyMatch`](#Any-Match-1) | Returns true if any item in stream matches predicate | `$stream->anyMatch($predicate)` |
| [`arePermutationsWith`](#Are-Permutations-With) | Returns true if all iterables permutations of stream | `$stream->arePermutationsWith(...$iterables)` |
| [`arePermutationsCoerciveWith`](#Are-Permutations-Coercive-With) | Returns true if all iterables permutations of stream with type coercion | `$stream->arePermutationsCoerciveWith(...$iterables)` |
| [`exactlyN`](#Exactly-N-1) | Returns true if exactly n items are true according to predicate | `$stream->exactlyN($n, $predicate)` |
| [`isSorted`](#Is-Sorted-1) | Returns true if stream is sorted in ascending order | `$stream->isSorted()` |
| [`isReversed`](#Is-Reversed-1) | Returns true if stream is sorted in reverse descending order | `$stream->isReversed()` |
| [`noneMatch`](#None-Match-1) | Returns true if none of the items in stream match predicate | `$stream->noneMatch($predicate)` |
| [`sameWith`](#Same-With) | Returns true if stream and all given collections are the same | `$stream->sameWith(...$iterables)` |
| [`sameCountWith`](#Same-Count-With) | Returns true if stream and all given collections have the same lengths | `$stream->sameCountWith(...$iterables)` |
| Terminal Operation | Description | Code Snippet |
|------------------------------------------------------------------|----------------------------------------------------------------------------------|--------------------------------------------------------|
| [`allMatch`](#All-Match-1) | Returns true if all items in stream match predicate | `$stream->allMatch($predicate)` |
| [`anyMatch`](#Any-Match-1) | Returns true if any item in stream matches predicate | `$stream->anyMatch($predicate)` |
| [`arePermutationsWith`](#Are-Permutations-With) | Returns true if all iterables permutations of stream | `$stream->arePermutationsWith(...$iterables)` |
| [`arePermutationsCoerciveWith`](#Are-Permutations-Coercive-With) | Returns true if all iterables permutations of stream with type coercion | `$stream->arePermutationsCoerciveWith(...$iterables)` |
| [`exactlyN`](#Exactly-N-1) | Returns true if exactly n items are true according to predicate | `$stream->exactlyN($n, $predicate)` |
| [`isPartitioned`](#Is-Partitioned-1) | Returns true if partitioned with items true according to predicate before others | `$stream::isPartitioned($predicate)` |
| [`isSorted`](#Is-Sorted-1) | Returns true if stream is sorted in ascending order | `$stream->isSorted()` |
| [`isReversed`](#Is-Reversed-1) | Returns true if stream is sorted in reverse descending order | `$stream->isReversed()` |
| [`noneMatch`](#None-Match-1) | Returns true if none of the items in stream match predicate | `$stream->noneMatch($predicate)` |
| [`sameWith`](#Same-With) | Returns true if stream and all given collections are the same | `$stream->sameWith(...$iterables)` |
| [`sameCountWith`](#Same-Count-With) | Returns true if stream and all given collections have the same lengths | `$stream->sameCountWith(...$iterables)` |

##### Reduction Terminal Operations
| Terminal Operation | Description | Code Snippet |
Expand Down Expand Up @@ -1523,6 +1525,23 @@ $boolean = Summary::exactlyN($ages, $n, $predicate);
// false
```

### Is Partitioned
Returns true if all elements of given collection that satisfy the predicate appear before all elements that don't.

```Summary::isPartitioned(iterable $data, callable $predicate = null): bool```

- Returns true for empty collection or for collection with single item.
- Default predicate if not provided is the boolean value of each data item.

```php
use IterTools\Summary;

$numbers = [0, 2, 4, 1, 3, 5];
$evensBeforeOdds = fn ($item) => $item % 2 === 0;

$boolean = Summary::isPartitioned($numbers, $evensBeforeOdds);
```

### Is Sorted
Returns true if elements are sorted, otherwise false.

Expand Down Expand Up @@ -2959,6 +2978,25 @@ $boolean = Stream::of($twoTruthsAndALie)->exactlyN($n);
// true
```

##### Is Partitioned
Returns true if all elements of given collection that satisfy the predicate appear before all elements that don't.

```$stream->isPartitioned(callable $predicate = null): bool```

- Returns true for empty collection or for collection with single item.
- Default predicate if not provided is the boolean value of each data item.

```php
use IterTools\Summary;

$numbers = [0, 2, 4, 1, 3, 5];
$evensBeforeOdds = fn ($item) => $item % 2 === 0;

$boolean = Stream::($numbers)
->isPartitioned($numbers, $evensBeforeOdds);
// true
```

##### Is Sorted
Returns true if iterable source is sorted in ascending order; otherwise false.

Expand Down

0 comments on commit f9f3688

Please sign in to comment.