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

Garrett Smith <>
Wed Mar 2 16:21:58 CET 2016


I recently implemented the second as "join" - ala string, but for arbitrary
separators and list elements.

I think the name "intersperse" is descriptive enough.

"intercalculate" no so much. I'd go with "join".

In the interest of consistency with other lists functions, I'd put the list
argument last in each case.

On Wed, Mar 2, 2016 at 8:54 AM Pierre Fenoll <> wrote:

> I find myself reimplementing the first one a lot, for use with iolists.
> The second one is string:join/2, right?
>
>
> > On 02 Mar 2016, at 06:47, Jesper Louis Andersen <
> > 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?
> >
> > --
> > J.
> > _______________________________________________
> > erlang-questions mailing list
> > 
> > http://erlang.org/mailman/listinfo/erlang-questions
> _______________________________________________
> erlang-questions mailing list
> 
> http://erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20160302/b0a5f1d5/attachment.html>


More information about the erlang-questions mailing list