Skip to content

Commit 5a97037

Browse files
committed
Nix.Builtins: replaceStrings: m refactor
Now we se the logic behind it
1 parent e75635f commit 5a97037

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

src/Nix/Builtins.hs

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -959,25 +959,24 @@ replaceStrings tfrom tto ts =
959959

960960
finish = makeNixString . LazyText.toStrict . Builder.toLazyText
961961

962-
go source resultAccum ctx = case lookupPrefix source of
963-
Nothing ->
964-
process source resultAccum ctx
965-
Just (prefix, replacementNS, rest) ->
966-
( if prefix == mempty
967-
then process
968-
else go
969-
) rest newResultAccum newCtx
970-
where
971-
replacement = Builder.fromText $ stringIgnoreContext replacementNS
972-
newResultAccum = resultAccum <> replacement
973-
additionalCtx = NixString.getContext replacementNS
974-
newCtx = ctx <> additionalCtx
962+
go source resultAccum ctx =
963+
case lookupPrefix source of
964+
Nothing ->
965+
process source resultAccum ctx
966+
Just (prefix, replacementNS, rest) ->
967+
(if prefix == mempty then process else go) rest newResultAccum newCtx
968+
where
969+
replacement = Builder.fromText $ stringIgnoreContext replacementNS
970+
newResultAccum = resultAccum <> replacement
971+
additionalCtx = NixString.getContext replacementNS
972+
newCtx = ctx <> additionalCtx
975973
where
976-
process t r =
977-
maybe
978-
(finish r)
979-
(\(h, t) -> go t (r <> Builder.singleton h))
980-
(Text.uncons t)
974+
process text result =
975+
maybe
976+
(finish result)
977+
(\(h, t) -> go t (result <> Builder.singleton h))
978+
(Text.uncons text)
979+
981980
toValue
982981
$ go (stringIgnoreContext ns) mempty
983982
$ NixString.getContext ns

0 commit comments

Comments
 (0)