Prelude.splitRecursive
Some checks failed
CI / test (push) Failing after 54s
CI / test-core (14, ubuntu-latest, 3.x, js) (push) Failing after 1m44s
CI / test-core (14, ubuntu-latest, 3.x, interp) (push) Failing after 1m40s
CI / test-core (14, ubuntu-latest, 3.x, nodejs) (push) Failing after 2m6s
CI / test-core (14, ubuntu-latest, 3.x, py) (push) Failing after 2m19s
CI / test-core (14, ubuntu-latest, 3.x, cpp) (push) Failing after 2m2s

This commit is contained in:
2025-11-14 14:33:15 -06:00
parent 57b61fea7e
commit 6aead2330a

View File

@@ -57,6 +57,7 @@ typedef HashableString = {
hashCode:()->Int
};
@:keep
class Prelude {
public static function hashableString(s:String):HashableString {
return {
@@ -404,6 +405,22 @@ class Prelude {
return filter(_splitByAll([s], delimiters));
}
/**
* Split a string by the first delimiter, then recursively split the substrings by
* the following delimiters in order.
* i.e. (splitRecursive "a:b::c:d" ["::" ":"]) returns [["a" "b"] ["c" "d"]]
*/
public static function splitRecursive(s:String, delimiters:Array<String>):Array<Dynamic> {
var parts = s.split(delimiters[0]);
return if (delimiters.length == 1) {
parts;
} else {
[for (part in parts) {
splitRecursive(part, delimiters.slice(1));
}];
}
}
public static function reverse<T>(l:kiss.List<T>):kiss.List<T> {
var c = l.copy();
c.reverse();