Skip to content

Commit

Permalink
Add missing DirectoryIterator example
Browse files Browse the repository at this point in the history
  • Loading branch information
mpetrovich committed Aug 19, 2018
1 parent 72bb1dd commit 9e73aa8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,21 @@ Dash\chain(new ArrayObject(['a' => 1, 'b' => 2, 'c' => 3, 'd' => 4]))
// === 5
```

With a `DirectoryIterator`:

```php
$iterator = new \FilesystemIterator(__DIR__, \FilesystemIterator::SKIP_DOTS);

$filenames = Dash\chain($iterator)
->reject(function ($fileinfo) {
return $fileinfo->isDir();
})
->map(function ($fileinfo) {
return pathinfo($fileinfo)['filename'];
})
->value();
```


### Currying
[`curry()`](docs/Operations.md#curry) and related operations can be used to create curried functions from any callable:
Expand Down
12 changes: 12 additions & 0 deletions tests/_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,18 @@ public function testReadmeExamples()
->value()
);

$iterator = new \FilesystemIterator(__DIR__, \FilesystemIterator::SKIP_DOTS);
$filenames = Dash\chain($iterator)
->reject(function ($fileinfo) {
return $fileinfo->isDir();
})
->map(function ($fileinfo) {
return pathinfo($fileinfo)['filename'];
})
->value();

$this->assertGreaterThan(10, count($filenames));

/*
Custom operation
*/
Expand Down

0 comments on commit 9e73aa8

Please sign in to comment.