private function sizeOf($value): int
    {
        if (is_string($value)) {
            return strlen($value);
        } elseif (is_array($value) || $value instanceof \Countable) {
            return count($value);
        }

        $traversable = $this->traversable($value);
        $key         = $traversable->key();
        $count       = iterator_count($traversable);
        // rewinds traversable to previous key to not change state of traversable
        // because iterator_count() changes the pointer
        $traversable->rewind();
        while ($traversable->valid() && $key !== $traversable->key()) {
            $traversable->next();
        }

        return $count;
    }