Skip to content

Commit

Permalink
Prefer Dash\Dash to Dash\_ and Dash\chain() to _::chain()
Browse files Browse the repository at this point in the history
  • Loading branch information
mpetrovich committed Mar 17, 2019
1 parent c041762 commit 7e2f2a2
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 40 deletions.
30 changes: 14 additions & 16 deletions bin/docs.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@

require_once 'vendor/autoload.php';

use Dash\_;

$sourceDir = $argv[1];
$destFilepath = $argv[2];
makeDocs($sourceDir, $destFilepath);

function makeDocs($sourceDir, $destFilepath)
{
$ops = _::chain(new FilesystemIterator($sourceDir, FilesystemIterator::SKIP_DOTS))
$ops = Dash\chain(new FilesystemIterator($sourceDir, FilesystemIterator::SKIP_DOTS))
->reject(function ($fileinfo) { return $fileinfo->isDir(); })
->map(function ($fileinfo) { return pathinfo($fileinfo)['filename']; })
->reject(function ($name) { return $name[0] === '_'; })
Expand All @@ -25,7 +23,7 @@ function makeDocs($sourceDir, $destFilepath)
})
->value();

$opDocs = _::chain($ops)
$opDocs = Dash\chain($ops)
->map('renderOp')
->join("\n")
->value();
Expand All @@ -46,7 +44,7 @@ function createOp($filepath)
$curriedFilepath = dirname($filepath) . '/Curry/' . basename($filepath);
$op->curriedFilepath = file_exists($curriedFilepath) ? $curriedFilepath : null;

$op->slug = _::chain(array_merge([$op->name], $op->aliases))
$op->slug = Dash\chain(array_merge([$op->name], $op->aliases))
->map(Dash\ary('strtolower', 1))
->join('--')
->value();
Expand Down Expand Up @@ -84,18 +82,18 @@ function parseDocblock($docblock)
$lines = explode("\n", $docblock);

// Incomplete
$op->isIncomplete = _::chain($lines)
$op->isIncomplete = Dash\chain($lines)
->any(function ($line) { return strpos($line, '@incomplete') === 0; })
->value();

// Description
$op->description = _::chain($lines)
$op->description = Dash\chain($lines)
->takeWhile(function ($line) { return strpos($line, '@') === false; })
->join("\n")
->value();

// Related
$op->related = _::chain($lines)
$op->related = Dash\chain($lines)
->filter(function ($line) { return strpos($line, '@see') === 0; })
->map(function ($line) {
$matches = [];
Expand All @@ -112,7 +110,7 @@ function parseDocblock($docblock)
->value();

// Alias
$op->aliases = _::chain($lines)
$op->aliases = Dash\chain($lines)
->filter(function ($line) { return strpos($line, '@alias') === 0; })
->first()
->thru(function ($line) {
Expand All @@ -124,7 +122,7 @@ function parseDocblock($docblock)
->value();

// Return value
$op->return = _::chain($lines)
$op->return = Dash\chain($lines)
->filter(function ($line) { return strpos($line, '@return') === 0; })
->map(function ($line) {
$matches = [];
Expand All @@ -140,7 +138,7 @@ function parseDocblock($docblock)
->value();

// Parameters
$allParamLines = _::dropWhile($lines, function ($line) {
$allParamLines = Dash\dropWhile($lines, function ($line) {
return strpos($line, '@param') !== 0;
});

Expand Down Expand Up @@ -168,7 +166,7 @@ function parseDocblock($docblock)
}

// Examples
$allExampleLines = _::dropWhile($lines, function ($line) {
$allExampleLines = Dash\dropWhile($lines, function ($line) {
return strpos($line, '@example') !== 0;
});

Expand Down Expand Up @@ -196,7 +194,7 @@ function renderOp($op)
{
$aliases = $op->aliases ? sprintf(' / %s', implode(' / ', $op->aliases)) : '';

$related = _::chain((array) $op->related)
$related = Dash\chain((array) $op->related)
->map(function ($opName) {
return "`$opName()`";
})
Expand All @@ -206,7 +204,7 @@ function renderOp($op)
$related = $related ? "See also: $related" : '';

if ($op->params) {
$paramsTable = _::reduce($op->params, function ($output, $param) {
$paramsTable = Dash\reduce($op->params, function ($output, $param) {
$type = str_replace('|', '\|', $param->type);
return $output . rtrim("`$param->name` | `$type` | $param->description") . "\n";
}, "Parameter | Type | Description\n--- | --- | :---\n");
Expand All @@ -226,7 +224,7 @@ function renderOp($op)
$returnTable = '';
}

$examples = _::chain($op->examples)
$examples = Dash\chain($op->examples)
->map(function ($example) {
$description = $example->description ? " {$example->description}" : '';
return <<<END
Expand Down Expand Up @@ -271,7 +269,7 @@ function renderOp($op)

function renderTableOfContents($ops)
{
$opSummaries = _::chain($ops)
$opSummaries = Dash\chain($ops)
->sort(function($op1, $op2) {
return strnatcmp($op1->name, $op2->name);
})
Expand Down
16 changes: 8 additions & 8 deletions docs/Operations.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Operation | Signature
[at](#at) | `at($iterable, $index, $default = null): mixed`
[average](#average--mean) / mean | `average($iterable): double\|null`
[call](#call) | `call(callable $callable /*, ...args */): mixed`
[chain](#chain) | `chain($input = null): Dash\_`
[chain](#chain) | `chain($input = null): Dash\Dash`
[compare](#compare) | `compare($a, $b): integer`
[contains](#contains--includes) / includes | `contains($iterable, $target, $comparator = 'Dash\equal'): boolean`
[currify](#currify) | `currify(callable $callable, array $args = [], $rotate = 1): function\|mixed`
Expand Down Expand Up @@ -393,18 +393,18 @@ chain


```php
chain($input = null): Dash\_
chain($input = null): Dash\Dash

# Curried: (all parameters required)
Curry\chain($input)
```
Creates a new chain. Alias for `_::chain()`.
Creates a new chain. Alias for `Dash::chain()`.


Parameter | Type | Description
--- | --- | :---
`$input` | `mixed` | (optional) Initial input value of the chain
**Returns** | `Dash\_` | A new chain
**Returns** | `Dash\Dash` | A new chain

**Example:**
```php
Expand Down Expand Up @@ -804,13 +804,13 @@ Parameter | Type | Description

**Example:**
```php
_::setCustom('double', function ($n) { return $n * 2; });
Dash::setCustom('double', function ($n) { return $n * 2; });

$double = Dash\custom('double');
$double(3);
// === 6

_::chain([1, 2, 3])->map(Dash\custom('double'))->value();
Dash\chain([1, 2, 3])->map(Dash\custom('double'))->value();
// === [2, 4, 6]
```

Expand Down Expand Up @@ -3180,7 +3180,7 @@ Parameter | Type | Description

**Example:**
```php
$result = _::chain([1, 3, 4])
$result = Dash\chain([1, 3, 4])
->filter('Dash\isOdd')
->tap(function ($value) {
// $value === [1, 3]
Expand Down Expand Up @@ -3214,7 +3214,7 @@ Parameter | Type | Description

**Example:**
```php
$result = _::chain([1, 3, 4])
$result = Dash\chain([1, 3, 4])
->filter('Dash\isOdd')
->thru(function ($value) {
// $value === [1, 3]
Expand Down
2 changes: 1 addition & 1 deletion src/Dash.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static function addGlobalAlias($alias = '__')
* Creates a new chain.
*
* @param mixed $input (optional) Initial input value of the chain
* @return Dash\_ A new chain
* @return self A new chain
*
* @example
Dash::chain([1, 2, 3])
Expand Down
6 changes: 3 additions & 3 deletions src/chain.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
namespace Dash;

/**
* Creates a new chain. Alias for `_::chain()`.
* Creates a new chain. Alias for `Dash::chain()`.
*
* @param mixed $input (optional) Initial input value of the chain
* @return Dash\_ A new chain
* @return Dash\Dash A new chain
*
* @example
Dash\chain([1, 2, 3])
Expand All @@ -17,5 +17,5 @@
*/
function chain($input = null)
{
return _::chain($input);
return Dash::chain($input);
}
4 changes: 2 additions & 2 deletions src/custom.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
* @return function The custom operation
*
* @example
_::setCustom('double', function ($n) { return $n * 2; });
Dash::setCustom('double', function ($n) { return $n * 2; });
$double = Dash\custom('double');
$double(3);
// === 6
_::chain([1, 2, 3])->map(Dash\custom('double'))->value();
Dash\chain([1, 2, 3])->map(Dash\custom('double'))->value();
// === [2, 4, 6]
*/
function custom($name)
Expand Down
2 changes: 1 addition & 1 deletion src/tap.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* @return mixed Original `$value`
*
* @example
$result = _::chain([1, 3, 4])
$result = Dash\chain([1, 3, 4])
->filter('Dash\isOdd')
->tap(function ($value) {
// $value === [1, 3]
Expand Down
2 changes: 1 addition & 1 deletion src/thru.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @return mixed Return value of `$interceptor($value)`
*
* @example
$result = _::chain([1, 3, 4])
$result = Dash\chain([1, 3, 4])
->filter('Dash\isOdd')
->thru(function ($value) {
// $value === [1, 3]
Expand Down
12 changes: 6 additions & 6 deletions tests/customTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class customTest extends PHPUnit_Framework_TestCase
{
public function test()
{
Dash\_::setCustom('double', function ($value) {
Dash\Dash::setCustom('double', function ($value) {
return $value * 2;
});

Expand All @@ -17,15 +17,15 @@ public function test()

$this->assertSame(
[2, 4, 6],
Dash\_::chain([1, 2, 3])->map(Dash\custom('double'))->value()
Dash\chain([1, 2, 3])->map(Dash\custom('double'))->value()
);

Dash\_::unsetCustom('double');
Dash\Dash::unsetCustom('double');
}

public function testCurried()
{
Dash\_::setCustom('double', function ($value) {
Dash\Dash::setCustom('double', function ($value) {
return $value * 2;
});

Expand All @@ -35,10 +35,10 @@ public function testCurried()

$this->assertSame(
[2, 4, 6],
Dash\_::chain([1, 2, 3])->map($custom('double'))->value()
Dash\chain([1, 2, 3])->map($custom('double'))->value()
);

Dash\_::unsetCustom('double');
Dash\Dash::unsetCustom('double');
}

public function testNumberOfArgsPreserved()
Expand Down
2 changes: 1 addition & 1 deletion tests/tapTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function testExamples()
{
ob_start();

$result = Dash\_::chain([1, 3, 4])
$result = Dash\chain([1, 3, 4])
->filter('Dash\isOdd')
->tap(function ($value) {
// $value === [1, 3]
Expand Down
2 changes: 1 addition & 1 deletion tests/thruTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function cases()

public function testExamples()
{
$result = Dash\_::chain([1, 3, 4])
$result = Dash\chain([1, 3, 4])
->filter('Dash\isOdd')
->thru(function ($value) {
// $value === [1, 3]
Expand Down

0 comments on commit 7e2f2a2

Please sign in to comment.