Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding intersperse to the API #421

Open
tchoutri opened this issue Nov 14, 2021 · 2 comments
Open

Adding intersperse to the API #421

tchoutri opened this issue Nov 14, 2021 · 2 comments

Comments

@tchoutri
Copy link

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.

@lehins
Copy link
Contributor

lehins commented Nov 15, 2021

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 lehins changed the title Adding interperse to the API Adding intersperse to the API Nov 15, 2021
@Shimuuar
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants