add object transforms
This commit is contained in:
parent
822b939ec8
commit
c11a615169
10
src/Transforms/index.php
Normal file
10
src/Transforms/index.php
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Copyright 2018 Kacper Donat
|
||||||
|
*
|
||||||
|
* @author Kacper "Kadet" Donat <kacper@kadet.net>
|
||||||
|
*
|
||||||
|
* Full license available in separate LICENSE file
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
40
src/Transforms/objects.php
Normal file
40
src/Transforms/objects.php
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Copyright 2018 Kacper Donat
|
||||||
|
*
|
||||||
|
* @author Kacper "Kadet" Donat <kacper@kadet.net>
|
||||||
|
*
|
||||||
|
* Full license available in separate LICENSE file
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Kadet\Functional\Transforms;
|
||||||
|
|
||||||
|
function getter($property)
|
||||||
|
{
|
||||||
|
return method('get'.ucfirst($property));
|
||||||
|
}
|
||||||
|
|
||||||
|
function property($property)
|
||||||
|
{
|
||||||
|
return function ($object) use ($property) {
|
||||||
|
if (method_exists($object, $getter = 'get'.ucfirst($property))) {
|
||||||
|
return $object->{$getter}();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $object->{$property};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function field($field)
|
||||||
|
{
|
||||||
|
return function ($object) use ($field) {
|
||||||
|
return $object->{$field};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function method($method, ...$args)
|
||||||
|
{
|
||||||
|
return function ($object) use ($method, $args) {
|
||||||
|
return $object->{$method}(...$args);
|
||||||
|
};
|
||||||
|
}
|
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
namespace Kadet\Functional;
|
namespace Kadet\Functional;
|
||||||
|
|
||||||
use function foo\func;
|
|
||||||
use Kadet\Functional\Predicate\AllOfPredicate;
|
use Kadet\Functional\Predicate\AllOfPredicate;
|
||||||
use Kadet\Functional\Predicate\AnyOfPredicate;
|
use Kadet\Functional\Predicate\AnyOfPredicate;
|
||||||
use Kadet\Functional\Predicate\ClosurePredicate;
|
use Kadet\Functional\Predicate\ClosurePredicate;
|
||||||
@ -14,6 +13,7 @@ use Kadet\Functional\Utils\FixedFunction;
|
|||||||
use Kadet\Functional\Utils\PartiallyAppliedFunction;
|
use Kadet\Functional\Utils\PartiallyAppliedFunction;
|
||||||
|
|
||||||
require_once __DIR__.'/Utils/index.php';
|
require_once __DIR__.'/Utils/index.php';
|
||||||
|
require_once __DIR__.'/Transforms/index.php';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $predicate
|
* @param $predicate
|
||||||
|
Loading…
Reference in New Issue
Block a user