intersperse
jfilip opened this issue · 14 comments
Very useful functions for combining arrays of monoids (like strings)
As string aren't arrays in purescript they actually currently have their own intercalate equivalent already joinWith (in purescript-strings).
Hmm, ok, not as generic as a monoid-intercalate, but good enough for what I'm doing now, thanks!
These would still be nice functions to have, do they belong here, or can they be put somewhere more general?
I guess they'd be like intercalate :: forall a. (Monoid a) => a -> [a] -> a, and monoid already depends on arrays, so putting it there would make sense.
👍 for adding this to monoids.
I wonder if there's a fold for this.
I'm working on that now actually.
I think intersperse should stay in foldable-traversable, but I also think a monomorphic Array.intercalate :: forall a. a -> Array a -> Array a would be a good thing to add here. Shall we reopen this?
Agh, got them the wrong way around.
Given that we all seem to always get these names wrong, it seems like they could have better names.
In any case, I'm all for a forall a. a -> Array a -> Array a in here.
There's joinWith for String, which is similar, but it does somewhat overload the meaning of join in the case of arrays. 🤷♂️ I guess it's not really joining necessarily either.
AFAIK the words don't have a common origin, but the first time I saw "intercalate" in the Haskell docs it occurred to me: "Ah, it intersperses and then it collates." the mnemonic really stuck. I'd very much appreciate having both functions.
I'm claiming this one. Will be submitting a PR shortly.