diff --git a/src/Transforms/index.php b/src/Transforms/index.php new file mode 100644 index 0000000..baa482d --- /dev/null +++ b/src/Transforms/index.php @@ -0,0 +1,10 @@ + + * + * Full license available in separate LICENSE file + */ + + diff --git a/src/Transforms/objects.php b/src/Transforms/objects.php new file mode 100644 index 0000000..6263fe8 --- /dev/null +++ b/src/Transforms/objects.php @@ -0,0 +1,40 @@ + + * + * 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); + }; +} \ No newline at end of file diff --git a/src/functions.php b/src/functions.php index 6c034b3..8cc83fc 100644 --- a/src/functions.php +++ b/src/functions.php @@ -2,7 +2,6 @@ namespace Kadet\Functional; -use function foo\func; use Kadet\Functional\Predicate\AllOfPredicate; use Kadet\Functional\Predicate\AnyOfPredicate; use Kadet\Functional\Predicate\ClosurePredicate; @@ -14,6 +13,7 @@ use Kadet\Functional\Utils\FixedFunction; use Kadet\Functional\Utils\PartiallyAppliedFunction; require_once __DIR__.'/Utils/index.php'; +require_once __DIR__.'/Transforms/index.php'; /** * @param $predicate