Fusonic\Linq\Linq::getSingle PHP Method

getSingle() private method

private getSingle ( $func, $throw )
    private function getSingle($func, $throw)
    {
        $source = $this->getWhereIteratorOrInnerIterator($func);
        $count = 0;
        $single = null;
        foreach ($source as $stored) {
            $count++;
            if ($count > 1) {
                throw new \RuntimeException("The input sequence contains more than 1 elements.");
            }
            $single = $stored;
        }
        if ($count == 0 && $throw) {
            throw new \RuntimeException("The input sequence contains no matching element.");
        }
        return $single;
    }