// laravel style
$collection = collect([1, 2, 3, 4, 5, 6]);
list($underThree, $aboveThree) = $collection->partition(function ($i) {
return $i < 3;
});
// versatile emulation
\VersatileCollections\GenericCollection::makeNew(
[1, 2, 3, 4, 5, 6]
)->reduce(
function($carry, $item) {
if(count($carry) <= 0) {
$carry['above_three'] = new \VersatileCollections\GenericCollection();
$carry['below_three'] = new \VersatileCollections\GenericCollection();
}
if( $item < 3 ) {
$carry['below_three'][] = $item;
} else {
$carry['above_three'][] = $item;
}
return $carry;
},
new \VersatileCollections\GenericCollection()
);