Refactor splits/2 using foreach syntax (remove private filter _nwise) (#3260)

This commit refactors `splits/2` implementation using `foreach` syntax
and reduces intermediate arrays. This refactoring removes an unnecessary
private (and undocumented) filter `_nwise` and closes #3148.
This commit is contained in:
itchyny authored and GitHub committed 2025-05-18 08:27:44 +09:00
1 parent 96d19ca2ee
commit b088e83a82
5 files changed
+37 -21

No files matched your search

+7
View File
@@ -64,6 +64,13 @@ splits(", *")
"ef"
"gh"
splits(",? *"; "n")
"ab,cd ef, gh"
"ab"
"cd"
"ef"
"gh"
sub("[^a-z]*(?<x>[a-z]+)"; "Z\(.x)"; "g")
"123abc456def"
"ZabcZdef"
+13 -1
View File
@@ -192,8 +192,20 @@ sub("(?<x>.)"; "\(.x)!")
"aB"
["AB","ab","cc"]
# splits and _nwise
# splits
[splits("")]
"ab"
["","a","b",""]
[splits("c")]
"ab"
["ab"]
[splits("a+"; "i")]
"abAABBabA"
["","b","BB","b",""]
[splits("b+"; "i")]
"abAABBabA"
["a","AA","a","A"]