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

splitOn for Data.ByteString/Data.ByteString.Lazy #100

Open
ezyang opened this issue Dec 7, 2016 · 2 comments
Open

splitOn for Data.ByteString/Data.ByteString.Lazy #100

ezyang opened this issue Dec 7, 2016 · 2 comments

Comments

@ezyang
Copy link
Contributor

ezyang commented Dec 7, 2016

As per http://stackoverflow.com/questions/1398322/split-bytestring-on-a-bytestring-instead-of-a-word8-or-char this is a commonly requested piece of functionality. Here is one possible implementation for Data.ByteString:

splitOn :: Str -> Str -> [Str]
splitOn needle haystack0 = go haystack0
  where
    l = length needle
    breaker = breakSubstring needle -- save preprocessing
    go s = let (pre, post) = breaker s
           in pre : if null post
                       then []
                       else go (drop l post)

However, for lazy bytestrings, we will need an implementation of breakSubstring for them.

@sjakobi
Copy link
Member

sjakobi commented Jun 25, 2020

Related to #30.

@Bodigrim
Copy link
Contributor

The common objection is that different people have different expectations for splitOn with regards to keeping delimiters and skipping empty chunks. But given that text already sports splitOn, it seems entirely reasonable to introduce splitOn to bytestring with the same semantics.

Equwece added a commit to Equwece/bytestring that referenced this issue Sep 21, 2023
The implementation is based on a @ezyang code snippet from haskell#100.
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