Proposal: Add a splitBy / splitOn in Data.List

Elliot Cameron eacameron at
Fri Nov 2 12:55:28 UTC 2018

I didn't realize cabal now supported scripting. I suppose that addresses a
large number of my use cases for having this.

I didn't mean choosing different delimiters but only a single multielement
delimiter, albeit that is also not flexible. If we also had a
multicharacter replace function then a single-element split would be more

I'm still in favor of providing one or two of the most common, most
flexible versions of this just to help newcomers from other languages that
have these functions in their standard libraries, but my opinion is not
very strongly held.

On Fri, Nov 2, 2018, 8:18 AM Theodore Lief Gannon <tanuki at wrote:

> If you accept more than one delimiter but drop them, you've lost info
> about which one caused each break and can't map them back. It's more
> generic to keep them, since you can still filter.
> On Fri, Nov 2, 2018, 4:39 AM Elliot Cameron <eacameron at wrote:
>> Despite these subtleties, I must confess I've often wanted to whip up a
>> quick script and been frustrated that these functions are missing from
>> base. For example using Haskell as a sed/awk alternative can be pleasant
>> *if* the functions you need are in base. What's more, in many years I've
>> only really wanted one or two versions of this.
>> What if we added the most flexible of versions and included only that?
>> This version would accept multicharacter delimiters, always throw them
>> away, and always produce a new entry in the result for every occurrence of
>> the delimiter. If you don't want the empty entries, you can filter. If you
>> don't want leading, you can dropWhile. If you want the delimiters back, you
>> can map. This seems like a nice trade-off for just being available in base.
>> On Fri, Nov 2, 2018, 1:51 AM Edward Kmett <ekmett at wrote:
>>> The main thing that prevented it from going into base is the number of
>>> subtleties about what precisely it means to properly "split" something.
>>> Most languages make fairly arbitrary calls on topics such as:
>>> * Do you split on list elements (e.g. ',') or list of elements, so you
>>> can multi-character delimiters ", "? What about multiple types of thing
>>> that are all delimiters, e.g. any whitespace character?
>>> * What do you do with the delimiters?
>>> * What happens with runs of delimiters?
>>> * What about initial or final runs of delimiters (e.g. leading spaces)?
>>> The end result was that a split package was written by Brent Yorgey
>>> back in 2008 or so that rather comprehensively covers the design space, and
>>> it was incorporated into the Haskell Platform.
>>> -Edward
>>> On Thu, Nov 1, 2018 at 1:34 PM Saurabh Nanda <saurabhnanda at>
>>> wrote:
>>>> This has certainly been discussed before. A quick Google search turned
>>>> up the following past discussions:
>>>>    -
>>>>    -
>>>> Is there anything blocking this discussion & implementation? Anything
>>>> that can be done to unblock it?
>>>> -- Saurabh.
>>>> _______________________________________________
>>>> Libraries mailing list
>>>> Libraries at
>>> _______________________________________________
>>> Libraries mailing list
>>> Libraries at
>> _______________________________________________
>> Libraries mailing list
>> Libraries at
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Libraries mailing list