有没有办法在 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/