Liquidsoap: How to iterate over list of strings

377 Views Asked by At

I would like to add a function to the on_connect parameter of input.harbor. The function gets the headers as a list of strings. Now, I want to iterate over the list to log each header line (for debugging purposes).

How can I achieve this? I have already found list.iter, but not sure how to apply it.

An example would help a lot.

1

There are 1 best solutions below

0
stollr On

After some try and error and further research I found the solution.

list.iter is indeed the way to go. Iterating over a list of strings ([string, string, ...]) would look like this:

myList = ["aa", "bb", "cc"]
list.iter(fun(item) -> print(item), myList)

# The output will look this way:
# aa
# bb
# cc

If you have a list of string pairs ([(string, string), (string, string), ...]) you have to do it slightly different:

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