Skip to content

Commit

Permalink
filta
Browse files Browse the repository at this point in the history
  • Loading branch information
dakujem committed Jul 17, 2024
1 parent d0862c1 commit c4df695
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,24 +223,29 @@ fn(mixed $carry, mixed $value, mixed $key): mixed

### Filtering: `filter`

Create a generator that yields only the items of the input collection that the predicate returns _truthy_ for.

```php
use Dakujem\Toru\Itera;

Itera::filter(iterable $input, callable $predicate): iterable
```

Filter elements out based on a callable predicate.
When the predicate returns _falsey_, the element is rejected.
Accept and eliminate elements based on a callable predicate.
When the predicate returns _truthy_, the element is accepted and yielded.
When the predicate returns _falsey_, the element is rejected and skipped.

The predicate signature is
```php
fn(mixed $value, mixed $key): bool
```

Similar to `array_filter`, `iter\filter`.

>
> Sidenote
>
> Native CallbackFilterIterator may be used for similar results
> Native `CallbackFilterIterator` may be used for similar results:
> ```php
> new CallbackFilterIterator(Itera::toIterator($input), $predicate)
> ```
Expand Down

0 comments on commit c4df695

Please sign in to comment.