Skip to content

Commit c582b33

Browse files
committed
String: NixString: rename accessors
1 parent 9e2ef07 commit c582b33

File tree

2 files changed

+13
-26
lines changed

2 files changed

+13
-26
lines changed

src/Nix/Builtins.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,7 +1068,7 @@ replaceStringsNix tfrom tto ts =
10681068
updatedCtx = ctx <> replacementCtx
10691069

10701070
replacement = Builder.fromText $ ignoreContext replacementNS
1071-
replacementCtx = getContext replacementNS
1071+
replacementCtx = getStringContext replacementNS
10721072

10731073
-- The bug modifies the content => bug demands `pass` to be a real function =>
10741074
-- `go` calls `pass` function && `pass` calls `go` function
@@ -1079,7 +1079,7 @@ replaceStringsNix tfrom tto ts =
10791079
(\(c, i) -> go updatedCtx i $ output <> Builder.singleton c) -- If there are chars - pass one char & continue
10801080
(Text.uncons input) -- chip first char
10811081

1082-
toValue $ go (getContext string) (ignoreContext string) mempty
1082+
toValue $ go (getStringContext string) (ignoreContext string) mempty
10831083

10841084
removeAttrsNix
10851085
:: forall e t f m
@@ -1702,7 +1702,7 @@ getContextNix
17021702
getContextNix =
17031703
\case
17041704
(NVStr ns) ->
1705-
mkNVSet mempty <$> traverseToValue (getNixLikeContext $ toNixLikeContext $ getContext ns)
1705+
mkNVSet mempty <$> traverseToValue (getNixLikeContext $ toNixLikeContext $ getStringContext ns)
17061706
x -> throwError $ ErrorCall $ "Invalid type for builtins.getContext: " <> show x
17071707
<=< demand
17081708

@@ -1769,7 +1769,7 @@ appendContextNix tx ty =
17691769
newContextValues
17701770
$ getNixLikeContext $
17711771
toNixLikeContext $
1772-
getContext ns
1772+
getStringContext ns
17731773
)
17741774
$ ignoreContext ns
17751775

src/Nix/String.hs

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
module Nix.String
44
( NixString
5-
, getContext
5+
, getStringContext
66
, mkNixString
77
, StringContext(..)
88
, ContextFlavor(..)
@@ -103,11 +103,10 @@ type WithStringContext = WithStringContextT Identity
103103

104104
-- ** NixString
105105

106-
-- 2021-07-18: NOTE: It should be Context -> Contents.
107106
data NixString =
108107
NixString
109-
{ nsContext :: !(S.HashSet StringContext)
110-
, nsContents :: !Text
108+
{ getStringContext :: !(S.HashSet StringContext)
109+
, getStringContent :: !Text
111110
}
112111
deriving (Eq, Ord, Show, Generic)
113112

@@ -148,9 +147,6 @@ hasContext (NixString c _) = not $ null c
148147

149148
-- ** Getters
150149

151-
getContext :: NixString -> S.HashSet StringContext
152-
getContext = nsContext
153-
154150
fromNixLikeContext :: NixLikeContext -> S.HashSet StringContext
155151
fromNixLikeContext =
156152
S.fromList . (uncurry toStringContexts <=< M.toList . getNixLikeContext)
@@ -258,18 +254,9 @@ intercalateNixString :: NixString -> [NixString] -> NixString
258254
intercalateNixString _ [] = mempty
259255
intercalateNixString _ [ns] = ns
260256
intercalateNixString sep nss =
261-
uncurry NixString $ mapPair intertwine unpackNss
262-
where
263-
264-
intertwine :: ([HashSet StringContext] -> HashSet StringContext, [Text] -> Text)
265-
intertwine =
266-
( S.unions . (:) (nsContext sep)
267-
, Text.intercalate (nsContents sep)
268-
)
269-
270-
unpackNss :: ([HashSet StringContext], [Text])
271-
unpackNss = (fnss nsContext, fnss nsContents)
272-
where
273-
fnss :: (NixString -> b) -> [b]
274-
fnss = (`fmap` nss) -- do once
275-
257+
uncurry NixString $
258+
mapPair
259+
(S.unions . (one (getStringContext sep) <>) . (getStringContext <$>)
260+
, Text.intercalate (getStringContent sep) . (getStringContent <$>)
261+
)
262+
$ dup nss

0 commit comments

Comments
 (0)