当我尝试映射字符串时,我得到:
Exception: Sequence does not respond to 'map'
显然,Io没有为序列实现map
方法。那么如何将字符串序列转换为字符列表呢?
答案 0 :(得分:0)
Io目前没有Sequence asList方法,但可以轻松添加。
Range
s := "abc"
# From StackOverflow
# http://stackoverflow.com/questions/4255123/how-do-i-convert-a-string-to-a-list-in-io/4256258#4256258
Sequence asList := method(
result := list()
self foreach(x,
result append(x)
)
)
s asList map(c,
"Char: #{c}" interpolate println
)
输出:
Char: a
Char: b
Char: c