Is there any haskell function to concatenate list with separator?

前端 未结 5 1536
庸人自扰
庸人自扰 2020-12-07 16:06

Is there a function to concatenate elements of a list with a separator? For example:

> foobar \" \" [\"is\",\"there\",\"such\",\"a\",\"function\",\"?\"]
[         


        
5条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-07 16:44

    It's not hard to write one-liner using foldr

    join sep xs = foldr (\a b-> a ++ if b=="" then b else sep ++ b) "" xs
    join " " ["is","there","such","a","function","?"]
    

提交回复
热议问题