purescript/purescript-lists

would you be interested in adding an `intersperse` function?

danse opened this issue · 4 comments

danse commented

if you think it's a good idea, i will try to put together a pull request

paf31 commented

We have intercalate in monoids, but this seems like it'd be worth having here.

danse commented

so ... can the same effect be achieved by using intercalate? and if so, do you picture the body of intersperse here to rely on intercalate and the monoidal instance?

paf31 commented

You could always do something like intercalate [x] (map singleton xs) but that's hardly ideal. If we did add it here, it should probably be monomorphic and tail recursive.

danse commented

i realise that this could be a long shot for me giving my current availability and knowledge of Purescript. i built my naive implementation that fixes my probem (i was actually working with Arrays), but contributing it to the library requires a familiarity with the type classes that i still don't have.

it could still be worth to use this issue to collect related information. i see that there is a similar issue on arrays, and as far as i understand the recommended solution there is to use a monoid or foldable instance. it's difficult for me at the moment to reason about the efficiency and to figure out whether the same approach should be used for both arrays or lists or whether lists would work better with a dedicated implementation