diff --git a/src/ArrayExpressionLanguageProvider.php b/src/ArrayExpressionLanguageProvider.php index 960c2af..73851ba 100644 --- a/src/ArrayExpressionLanguageProvider.php +++ b/src/ArrayExpressionLanguageProvider.php @@ -28,6 +28,7 @@ public function getFunctions(): array new List_('list'), new FilterList('filterList'), new MapValues('mapValues'), + new NotEmpty('notEmpty') ]; } } diff --git a/src/NotEmpty.php b/src/NotEmpty.php new file mode 100644 index 0000000..2b691b3 --- /dev/null +++ b/src/NotEmpty.php @@ -0,0 +1,31 @@ +compile(...)->bindTo($this), + $this->evaluate(...)->bindTo($this) + ); + } + + private function compile() + { + return << \$carry && \$item !== null + PHP; + } + + private function evaluate(array $context, string $separator): callable + { + return fn ($carry, $item) => $carry && $item !== null; + } +}