protected function _countIterable($iterable)
    {
        $resolve = function ($it) {
            try {
                return $this->_resolveIterator($it, function ($it) {
                    return $it instanceof Countable;
                });
            } catch (RootException $e) {
                return;
            }
        };

        if ($iterable instanceof stdClass) {
            $iterable = (array) $iterable;
        }

        if (is_array($iterable) || $iterable instanceof Countable) {
            return count($iterable);
        }

        if ($countable = $resolve($iterable)) {
            return count($countable);
        }

        return iterator_count($iterable);
    }