Skip to content

Explain the empty components in splitWith's documentation - #728

Open
swinilohani616-dot wants to merge 2 commits into
haskell:masterfrom
swinilohani616-dot:splitwith-docs
Open

swinilohani616-dot wants to merge 2 commits into
haskell:masterfrom
swinilohani616-dot:splitwith-docs

Conversation

@swinilohani616-dot

@swinilohani616-dot swinilohani616-dot commented Nov 18, 2026 •

Copy link
Copy Markdown

Fixes #560.

The splitWith example confused people because it's not obvious where the empty strings come from. As
suggested in the issue, this just repeats the intercalate law from the split docs, which makes it clear:
split on c, glue the pieces back together with c, and you get the original string.

intercalate [c] . splitWith (== c) == id

I added the same line to each module that has splitWith, worded the way split already has it.

The splitWith example shows empty strings in the result, but the
documentation only mentioned the case of two adjacent separators, which
left the leading and trailing empty components unexplained. Spell out
that n separators give n + 1 components and when a component is empty,
and add the laws relating splitWith to split and intercalate, as
suggested in the issue. The laws are stated for a predicate of the form
(== w), since rejoining can't recover the input when the predicate
matches several different separators.

Fixes haskell#560
@Bodigrim

Copy link
Copy Markdown
Contributor

Sorry, but that's too verbose, especially repeated 5 times across different modules. #560 suggests repeating the law connecting intercalate and splitWith, let's do just that and nothing more.

As suggested in review, drop the extra explanation and keep just the
law connecting splitWith and intercalate, matching how split documents
it.
@swinilohani616-dot

Copy link
Copy Markdown
Author

Sorry, but that's too verbose, especially repeated 5 times across different modules. #560 suggests repeating the law connecting intercalate and splitWith, let's do just that and nothing more.

Makes sense, thanks! I've cut it down to just the intercalate law, written the same way split documents it. I kept that one line in each module that has splitWith, since they each have the matching law under split, but I'm happy to keep it to Data.ByteString.Char8 only if you'd prefer.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add to splitWith documentation

2 participants