Skip to content

Autoformat Readme #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 26, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ If your variable is already an instance of `Traversable` (i.e. an `Iterator`, an
If your variable is an array, the function converts it to an `ArrayIterator`.

Usage:

```php
use function BenTools\IterableFunctions\iterable_to_traversable;

var_dump(iterable_to_traversable(['foo', 'bar'])); // \ArrayIterator(['foo', 'bar'])
var_dump(iterable_to_traversable(new \ArrayIterator(['foo', 'bar']))); // \ArrayIterator(['foo', 'bar'])
```


iterable_map()
--------------

Expand Down Expand Up @@ -102,6 +102,7 @@ foreach (iterable_filter($generator()) as $item) {
```

Of course you can define your own filter:

```php
use function BenTools\IterableFunctions\iterable_filter;

Expand All @@ -126,6 +127,7 @@ Iterable fluent interface
The `iterable` function allows you to wrap an iterable and apply some common operations.

With an array input:

```php
use function BenTools\IterableFunctions\iterable;
$data = [
Expand All @@ -138,6 +140,7 @@ $iterable = iterable($data)->filter(fn($eatable) => 'rock' !== $eatable)->map('s
```

With a traversable input:

```php
use function BenTools\IterableFunctions\iterable;
$data = [
Expand All @@ -152,20 +155,22 @@ $iterable = iterable($data())->filter(fn($eatable) => 'rock' !== $eatable)->map(
```

Array output:

```php
$iterable->asArray(); // array ['banana', 'pineapple']
```


Installation
============

With composer (they'll be autoloaded):

```
composer require bentools/iterable-functions
```

Or manually:

```php
require_once '/path/to/this/library/src/iterable-functions.php';
```
Expand Down