elephox / pie
This package is abandoned and no longer maintained.
The author suggests using the elephox/collection package instead.
Elephox PIE library.
dev-main
2022-01-11 00:09 UTC
Requires
- php: ~8.1.0 || ~8.2.0
- jetbrains/phpstorm-attributes: ^1.0
This package is auto-updated.
Last update: 2022-01-19 01:57:35 UTC
README
This library (or rather module) was inspired by C#s LINQ library.
However, it is not a full-featured LINQ library. It is only a small subset of the functionality since PHP cannot fully support all the syntactic sugar. For example the main feature of LINQ, SQL-like syntax directly in source, is not supported since it would require you to compile/transpile your code.
The main idea however is to provide a way to iterate over a collection of objects in a more natural way like you can do with IEnumerable
s in C#.
Examples
<?php declare(strict_types=1); use Elephox\PIE\PIE; $array = [5, 2, 1, 4, 3]; $pie = PIE::from($array); $pie->orderBy(fn (int $item) => $item) ->select(function (int $item) { echo $item; }); // output: 12345 $pie->where(fn (int $item) => $item % 2 === 0) ->select(function (int $item) { echo $item; }); // output: 24