From f765e4f33e141e1d542d9af71098a111b2f01737 Mon Sep 17 00:00:00 2001 From: Eman Resu <78693624+quatquatt@users.noreply.github.com> Date: Mon, 11 May 2026 12:25:37 -0400 Subject: [PATCH] lib.strings.splitStringBy: bring map into the inner loop --- lib/strings.nix | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/lib/strings.nix b/lib/strings.nix index 3fb5d7994440..f6ba4ca7e07b 100644 --- a/lib/strings.nix +++ b/lib/strings.nix @@ -1804,31 +1804,27 @@ rec { predicate: keepSplit: str: let len = stringLength str; + withContext = addContextFrom str; # Helper function that processes the string character by character go = pos: currentPart: result: # Base case: reached end of string if pos == len then - result ++ [ currentPart ] + result ++ [ (withContext currentPart) ] else let currChar = substring pos 1 str; prevChar = if pos > 0 then substring (pos - 1) 1 str else ""; - isSplit = predicate prevChar currChar; in - if isSplit then + if predicate prevChar currChar then # Split here - add current part to results and start a new one - let - newResult = result ++ [ currentPart ]; - newCurrentPart = if keepSplit then currChar else ""; - in - go (pos + 1) newCurrentPart newResult + go (pos + 1) (if keepSplit then currChar else "") (result ++ [ (withContext currentPart) ]) else # Keep building current part go (pos + 1) (currentPart + currChar) result; in - if len == 0 then [ (addContextFrom str "") ] else map (addContextFrom str) (go 0 "" [ ]); + if len == 0 then [ (withContext "") ] else go 0 "" [ ]; /** Returns a string without the specified prefix, if the prefix matches.