public function groupByCallable(Nodes $nodes, callable $fn)
{
$grouping = [];
foreach ($nodes as $node) {
$key = $fn($node);
if (!isset($grouping[$key])) {
$grouping[$key] = [];
}
$grouping[$key][] = $node;
}
foreach ($grouping as $key => &$nodeList) {
$nodeList = $nodes->spawn($nodeList);
}
return $grouping;
}