如何在Io中映射字符串中的字符?

时间:2011-10-10 05:18:41

标签: string list map io sequence

当我尝试映射字符串时,我得到:

Exception: Sequence does not respond to 'map'

显然,Io没有为序列实现map方法。那么如何将字符串序列转换为字符列表呢?

1 个答案:

答案 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