Liquidsoop:如何迭代字符串列表



我想为input.harboron_connect参数添加一个函数。函数以字符串列表的形式获取标题。现在,我想对列表进行迭代,以记录每个标题行(出于调试目的(。

我怎样才能做到这一点?我已经找到了list.iter,但不知道如何应用它。

举个例子会有很大帮助。

经过一番尝试和进一步研究,我找到了解决方案。

list.iter确实是一条路。在字符串列表([string, string, ...](上迭代如下:

myList = ["aa", "bb", "cc"]
list.iter(fun(item) -> print(item), myList)
# The output will look this way:
# aa
# bb
# cc

如果你有一个字符串对列表([(string, string), (string, string), ...](,你必须做一些稍微不同的事情:

myList = [("a", "aaa"), ("b", "bbb"), ("c", "ccc")]
list.iter(
fun(item) -> print(
fst(item) ^ " => " ^ snd(item)
),
myList
)
# This will results in:
# a => aaa
# b => bbb
# c => ccc

最新更新