[erlang-questions] Proposal: add lists:intersperse/2 and lists:intercalate/2

Siraaj Khandkar siraaj@REDACTED
Mon Apr 11 14:59:19 CEST 2016


I think my personal reservation about the name "intersperse" is 
addressed by the possibility of later extending to include interval 
specification, something like this:

     intersperse(A, [A], Interval) -> [A]
         when Interval :: random | {regular, pos_integer()} | ... .

where the default is thought of as {regular, 1}.


P.S. I'm crossing my fingers, hoping Robert will not like "join"! :-)


On 4/11/16 8:06 AM, Jesper Louis Andersen wrote:
> Reviving this. There is now a PR for the proposal:
>
> https://github.com/erlang/otp/pull/1012
>
> The name is hard. I'm on the verge of asking Robert Virding what it should
> be and then use him as the BDFL. I'm not going to ask Joe, since then we
> would have disagreement between him and Robert :)
>
>
>
> On Wed, Mar 2, 2016 at 3:47 PM, Jesper Louis Andersen <
> jesper.louis.andersen@REDACTED> wrote:
>
>> Hi Erlangers,
>>
>> I'd really like to add two functions to the lists module from Haskell:
>>
>> intersperse(List, Seperator) produces a list where each element is
>> separated by separator, i.e.
>>
>> X = [1,2,3]
>> [1, x, 2, x, 3] = lists:intersperse(X, x),
>>
>> and it's cousin, intercalate(ListOfLists, Separator) is
>> append(intersperse(ListOfLists, Seperator)), i.e,
>>
>> Y = ["a", "b", "c"]
>> "a, b, c" = lists:intercalate(Y, ", "),
>>
>> The implementations are straightforward and easy to write tests for, even
>> property based tests if needed.
>>
>> The rationale for this proposal is that I find myself implementing this
>> function again and again in every project I write, and it is highly
>> generic. It belongs in a typical list module. OCaml libraries add it.
>> Haskell's Data.List has it. I believe Erlang, being a practical language,
>> should have it as well.
>>
>> Thoughts?



More information about the erlang-questions mailing list