Skip to content

Commit

Permalink
downgrade arrow functions to keep minimum required PHP version at 7.2
Browse files Browse the repository at this point in the history
  • Loading branch information
meszaros-lajos-gyorgy committed Nov 26, 2022
1 parent f62ca3b commit fcda92a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
36 changes: 27 additions & 9 deletions src/A.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,23 +165,35 @@ public static function sortByKey(
switch ($type) {
case 'string':
if ($direction === 'desc') {
$sorter = fn ($a, $b) => strcasecmp(O::prop($key, $b), O::prop($key, $a));
$sorter = function ($a, $b) use ($key) {
return strcasecmp(O::prop($key, $b), O::prop($key, $a));
};
} else {
$sorter = fn ($a, $b) => strcasecmp(O::prop($key, $a), O::prop($key, $b));
$sorter = function ($a, $b) use ($key) {
return strcasecmp(O::prop($key, $a), O::prop($key, $b));
};
}
break;
case 'date':
if ($direction === 'desc') {
$sorter = fn ($a, $b) => strtotime(O::prop($key, $b)) - strtotime(O::prop($key, $a));
$sorter = function ($a, $b) use ($key) {
return strtotime(O::prop($key, $b)) - strtotime(O::prop($key, $a));
};
} else {
$sorter = fn ($a, $b) => strtotime(O::prop($key, $a)) - strtotime(O::prop($key, $b));
$sorter = function ($a, $b) use ($key) {
return strtotime(O::prop($key, $a)) - strtotime(O::prop($key, $b));
};
}
break;
default:
if ($direction === 'desc') {
$sorter = fn ($a, $b) => O::prop($key, $b) - O::prop($key, $a);
$sorter = function ($a, $b) use ($key) {
return O::prop($key, $b) - O::prop($key, $a);
};
} else {
$sorter = fn ($a, $b) => O::prop($key, $a) - O::prop($key, $b);
$sorter = function ($a, $b) use ($key) {
return O::prop($key, $a) - O::prop($key, $b);
};
}
break;
}
Expand Down Expand Up @@ -391,16 +403,22 @@ function ($acc, $arg) {
public static function zipObj(array $keys, array $values): object
{
$_keys = self::uniq(self::concat(self::keys($keys), self::keys($values)));
$_keys = self::filter(fn ($key) => array_key_exists($key, $keys) && array_key_exists($key, $values), $_keys);
return self::reduce(fn ($result, $key) => O::assoc($keys[$key], $values[$key], $result), new stdClass(), $_keys);
$_keys = self::filter(function ($key) use ($keys, $values) {
return array_key_exists($key, $keys) && array_key_exists($key, $values);
}, $_keys);
return self::reduce(function ($result, $key) use ($keys, $values) {
return O::assoc($keys[$key], $values[$key], $result);
}, new stdClass(), $_keys);
}

// A::without([1, 3], [1, 2, 3, 4, 5]) -> [2, 4, 5]
public static function without($excludedItems, array $values): array
{
return self::values(self::reduce(function ($values, $excludedItem) {
if (self::includes($excludedItem, $values)) {
$index = self::findIndex(fn ($value) => $value === $excludedItem, $values);
$index = self::findIndex(function ($value) use ($excludedItem) {
return $value === $excludedItem;
}, $values);
unset($values[$index]);
}

Expand Down
4 changes: 3 additions & 1 deletion src/F.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ class F
{
public static function complement(callable $fn): callable
{
return fn(...$args) => !$fn(...$args);
return function (...$args) use ($fn) {
return !$fn(...$args);
};
}
}

0 comments on commit fcda92a

Please sign in to comment.