vector icon indicating copy to clipboard operation
vector copied to clipboard

Adding `intersperse` to the API

Open tchoutri opened this issue 2 years ago • 2 comments

I would like to suggest the addition of intersperse :: a -> Vector a -> Vector a to the API.

I have a prototype that I reuse in my projects, that reads:

intercalateVec :: Text -> Vector Text -> Vector Text                
intercalateVec sep vector =                                         
  if V.null vector                                                  
  then vector                                                       
  else V.tail $ V.concatMap (\word -> V.fromList [sep, word]) vector

But I would be interested to know if a better implementation is possible.

tchoutri avatar Nov 14 '21 21:11 tchoutri

I pretty sure it should be possible to get an efficient version implemented of this at the stream level. In fact, here is a drop in implementation for it from text:

https://github.com/haskell/text/blob/fdc938628efe9ecf86e7d11128c4c7cc66d1071a/src/Data/Text/Internal/Fusion/Common.hs#L457-L469

We should really unify streaming functions from text with vector into a single package. Have no clue how much work that would be though.

lehins avatar Nov 15 '21 02:11 lehins

I mark this issue "help-wanted". Contributions are welcome

Shimuuar avatar Jan 16 '24 08:01 Shimuuar