iterator - 任意类型的范围

标签 iterator go range

有没有办法在 Go 中生成任意类型 range?例如,Python 提供了 __iter__(),这非常有用。我尝试搜索答案,但没有找到任何结果。

最佳答案

您已成功搜索,Go 中不支持任意类型。

来自specs :

RangeClause = ( ExpressionList "=" | IdentifierList ":=" ) "range" Expression .

The expression on the right in the "range" clause is called the range expression, which may be an array, pointer to an array, slice, string, map, or channel permitting receive operations.

关于iterator - 任意类型的范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17833258/

相关文章:

go - context中的值不能在不同的包中传输?

go - 具有If Else条件的正则表达式

go - 将 curl 请求转换为 Golang

python - Python中的全范围随机数

java - 制作/实现数组列表的迭代器 - Java

loops - 你如何在 AppleScript 中循环访问菜单?

iterator - 在 Rust 中迭代切片的值而不是引用?

类中的 C++ 迭代器

数字搜索范围(在搜索中使用实数)

mysql - 评估mysql日期范围