haskell / haskell/text

Add a function to split text at the first occurrence of a character

Open
#625 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
Haskell
Stars
421
Forks
163
PR merge metrics
No merged PRs in 30d

Description

I was surprised not to find a function in the library to split a text on the first match of a character/text/predicate, with the matched part discarded.
This is not difficult to write using `breakOn` and `drop`, but I think a function implemented with the internals of the library might have better performance.

```haskell
split1 :: Char -> Text -> (Text, Text)
split1 c = (id *** drop 1) . (breakOn $ singleton c)
```

See [a similar function](https://hackage.haskell.org/package/byteslice-0.2.14.0/docs/Data-Bytes.html#v:split1) (previously called `splitOnce`) in the `byteslice` package, and [a question on Stack Overflow](https://stackoverflow.com/questions/40297001/split-a-list-at-the-first-occurrence-of-an-element) about `splitAtfirst`.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.