private function getLength($value): int {
    if (is_array($value) || $value instanceof \Countable) return count($value);
    if ($value instanceof \Traversable) return iterator_count($value);
    if (is_string($value)) return mb_strlen($value);
    throw new \InvalidArgumentException("The specified value is not iterable: $value");
  }