Skip to content

Commit d551b89

Browse files
committed
Allow custom computations inside string contexts
1 parent e0215ae commit d551b89

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/Nix/String.hs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ module Nix.String
3232
, addStringContext
3333
, addSingletonStringContext
3434
, runWithStringContextT
35+
, runWithStringContextT'
3536
, runWithStringContext
37+
, runWithStringContext'
3638
)
3739
where
3840

@@ -231,6 +233,16 @@ runWithStringContextT :: Monad m => WithStringContextT m Text -> m NixString
231233
runWithStringContextT (WithStringContextT m) =
232234
uncurry NixString <$> runWriterT m
233235

236+
-- | Run an action that manipulates nix strings, and collect the contexts encountered.
237+
-- Warning: this may be unsafe, depending on how you handle the resulting context list.
238+
runWithStringContextT' :: Monad m => WithStringContextT m a -> m (a, S.HashSet StringContext)
239+
runWithStringContextT' (WithStringContextT m) = runWriterT m
240+
234241
-- | Run an action producing a string with a context and put those into a 'NixString'.
235242
runWithStringContext :: WithStringContextT Identity Text -> NixString
236243
runWithStringContext = runIdentity . runWithStringContextT
244+
245+
-- | Run an action that manipulates nix strings, and collect the contexts encountered.
246+
-- Warning: this may be unsafe, depending on how you handle the resulting context list.
247+
runWithStringContext' :: WithStringContextT Identity a -> (a, S.HashSet StringContext)
248+
runWithStringContext' = runIdentity . runWithStringContextT'

0 commit comments

Comments
 (0)