Liquidsoap:如何迭代字符串列表

时间:2021-01-12 06:59:00

标签: liquidsoap

我想向 input.harboron_connect 参数添加一个函数。该函数将标题作为字符串列表获取。 现在,我想遍历列表以记录每个标题行(用于调试目的)。

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

举个例子会有很大帮助。

1 个答案:

答案 0 :(得分:1)

经过一些尝试和错误以及进一步的研究,我找到了解决方案。

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