mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-09 05:20:32 +00:00
refactor implementation to avoid bug
This commit is contained in:
parent
efae03240e
commit
cf05fe03e9
1 changed files with 9 additions and 8 deletions
|
@ -1285,18 +1285,19 @@ splitOn = \elements, delimiter ->
|
|||
## ```
|
||||
splitOnList : List a, List a -> List (List a) where a implements Eq
|
||||
splitOnList = \elements, delimiter ->
|
||||
if delimiter == [] then
|
||||
[elements]
|
||||
else
|
||||
|
||||
help = \remaining, chunks, currentChunk ->
|
||||
when remaining is
|
||||
[] -> List.append chunks currentChunk
|
||||
_ if List.startsWith remaining delimiter ->
|
||||
help (List.dropFirst remaining (List.len delimiter)) (List.append chunks currentChunk) []
|
||||
[x, .. as rest] ->
|
||||
if List.startsWith remaining delimiter then
|
||||
help (List.dropFirst remaining (List.len delimiter)) (List.append chunks currentChunk) []
|
||||
else
|
||||
help rest chunks (List.append currentChunk x)
|
||||
|
||||
[x, .. as rest] -> help rest chunks (List.append currentChunk x)
|
||||
help elements [] []
|
||||
if delimiter == [] then
|
||||
[elements]
|
||||
else
|
||||
help elements [] []
|
||||
|
||||
## DEPRECATED: will be removed soon
|
||||
split : List elem, U64 -> { before : List elem, others : List elem }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue