What would we think of adding split_if to the List builtin?
IE:
split_if : List a, (a -> Bool) -> List (List a)
Can you list the current set of split functions for reference?
split_atsplit_onsplit_on_listsplit_firstsplit_lastYou could also argue that chunks_of belongs in that list.
So for example you could do :
chars |> List.split_if(|c| c >= 'A' and c <= 'Z')
instead of:
chars |> List.split_on_list(['A', .. 'Z'])
Sounds reasonable.
Though honestly I'm not sure I like the names of these functions overall....not the clearest....but I don't have concrete suggestions at the moment. Also, not sure what the limit is for number of split function variations. Would be nice to think about a comprehensive set with clean names.
Or if you wanted to do something like split_if(chars, |c| !is_alphanumeric(c)), you need to use List.walk. Not the end of the world, but seems like this deserves a split function to me...
This doesn't answer your concern about the nomenclature, but if we're concerned about too many split functions, I think split_if is a good replacement for split_on_list, and even split_on if we wanted. split_if can cover both of those use cases.
list |> List.split_if(|e| e == delim)list |> List.split_if(|e| List.contains(delims, e))For discussion: a reduced set of more comprehensive/versatile split functions, which covers all current functionality, pus some:
split_at-- no changesplit_if -- replaces split_on, split_on_list, + more functionalitysplit_once_if -- (w/List.reverse for last), replaces split_first/split_last, and more versatile.This would take us from 5 to 3 split functions, cover all current functionality, and add new functionality.
I wouldn't depends on List.reverse for now.
It is expensive
Oh, I was thinking that it was just a bit flip... that changes things.
Not currently
Probably will be optimized once we have iterators
But no detailed plans yet
So then maybe split_first_if/split_last_if?
We'd be down to 4 split functions from 5, with more versatility, but not sure if I love those names...
Haha, yeah.
Naming is hard
Anyone else have thoughts on List splitting functions?
| Current | Proposed | Proposed signature |
|---|---|---|
| split_at | split_at | List a, U64 -> { before: List a, others: List a } # no change |
| split_on | split_if | List a, (a -> Bool) -> List (List a) |
| split_on_list | split_if | |
| split_first | split_first_if | List a, (a -> Bool) -> Result { before: List a, after: List a } [NotFound] |
| split_last | split_last_if | List a, (a -> Bool) -> Result { before: List a, after: List a } [NotFound] |
Last updated: Jun 16 2026 at 16:19 UTC