Skip to content

Commit d53cb65

Browse files
committed
Nix.Builtins: replaceStrings: m refactor: to maybe
1 parent 260c3b9 commit d53cb65

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

src/Nix/Builtins.hs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -961,21 +961,20 @@ replaceStrings tfrom tto ts =
961961

962962
go orig result ctx = case lookupPrefix orig of
963963
Nothing ->
964-
(case Text.uncons orig of
965-
Nothing ->
966-
finish result
967-
Just (h, t) ->
968-
go t (result <> Builder.singleton h)) ctx
964+
maybe
965+
(finish result)
966+
(\(h, t) -> go t (result <> Builder.singleton h))
967+
(Text.uncons orig)
968+
ctx
969969
Just (prefix, replacementNS, rest) ->
970970
(case prefix of
971971
"" ->
972-
case Text.uncons rest of
973-
Nothing ->
974-
finish (result <> Builder.fromText replacement)
975-
Just (h, t) ->
976-
go t (mconcat [ result
977-
, Builder.fromText replacement
978-
, Builder.singleton h ])
972+
maybe
973+
(finish (result <> Builder.fromText replacement))
974+
(\(h,t) -> go t (mconcat [ result
975+
, Builder.fromText replacement
976+
, Builder.singleton h ]))
977+
(Text.uncons rest)
979978
_prefix ->
980979
go rest (result <> Builder.fromText replacement)) (ctx <> newCtx)
981980
where

0 commit comments

Comments
 (0)