-
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
136 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace drupol\collection\Contract; | ||
|
||
/** | ||
* Interface Explodeable. | ||
*/ | ||
interface Explodeable | ||
{ | ||
/** | ||
* @param string ...$explodes | ||
* | ||
* @return \drupol\collection\Contract\Collection | ||
*/ | ||
public function explode(string ...$explodes): Base; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace drupol\collection\Operation; | ||
|
||
use drupol\collection\Contract\Operation; | ||
|
||
/** | ||
* Class Explode. | ||
*/ | ||
final class Explode implements Operation | ||
{ | ||
/** | ||
* @var string[] | ||
*/ | ||
private $explodes; | ||
|
||
/** | ||
* Explode constructor. | ||
* | ||
* @param string ...$explodes | ||
*/ | ||
public function __construct(string ...$explodes) | ||
{ | ||
$this->explodes = $explodes; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function on(iterable $collection): \Closure | ||
{ | ||
$callbacks = \array_map( | ||
static function ($explode) { | ||
return static function ($value) use ($explode) { | ||
return $value === $explode; | ||
}; | ||
}, | ||
$this->explodes | ||
); | ||
|
||
return (new Split(...$callbacks))->on($collection); | ||
} | ||
} |