public function getGroupByName($name) { return $this->getGroups()->then(function (array $groups) use($name) { foreach ($groups as $group) { if ($group->getName() === $name) { return $group; } } throw new ApiException('Group ' . $name . ' not found.'); }); }