Skip to content

Commit efffdfe

Browse files
committed
Value: {iterNValue: unflip 2nd arg, add iterNValueByDiscardWith, notes}
1 parent 22a2bbd commit efffdfe

File tree

4 files changed

+17
-10
lines changed

4 files changed

+17
-10
lines changed

src/Nix/Normal.hs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import Data.Set ( member
1919
)
2020
import Nix.Cited
2121
import Nix.Frames
22-
import Nix.String
2322
import Nix.Thunk
2423
import Nix.Value
2524

@@ -156,7 +155,7 @@ stubCycles
156155
-> NValue t f m
157156
stubCycles =
158157
iterNValue
159-
(\t _ ->
158+
(\_ t ->
160159
Free $
161160
NValue' $
162161
foldr

src/Nix/Pretty.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ exprFNixDoc = \case
307307

308308

309309
valueToExpr :: forall t f m . MonadDataContext f m => NValue t f m -> NExpr
310-
valueToExpr = iterNValue (\_ _ -> thk) (Fix . phi)
310+
valueToExpr = iterNValueByDiscardWith thk (Fix . phi)
311311
where
312312
thk = Fix . NSym $ "<expr>"
313313

@@ -372,7 +372,7 @@ prettyNThunk t =
372372

373373
-- | This function is used only by the testing code.
374374
printNix :: forall t f m . MonadDataContext f m => NValue t f m -> String
375-
printNix = iterNValue (\_ _ -> thk) phi
375+
printNix = iterNValueByDiscardWith thk phi
376376
where
377377
thk = toString thunkStubText
378378

src/Nix/Value.hs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -513,18 +513,26 @@ type NValue t f m = Free (NValue' t f m) t
513513

514514
-- ** Free
515515

516-
-- | @iter@
516+
-- | HOF of @iter@ from @Free@
517517
iterNValue
518518
:: forall t f m r
519519
. MonadDataContext f m
520-
=> (t -> (NValue t f m -> r) -> r)
520+
=> ((Free (NValue' t f m) t -> r) -> t -> r)
521521
-> (NValue' t f m r -> r)
522-
-> NValue t f m
522+
-> Free (NValue' t f m) t
523+
-> r
524+
iterNValue k f = iter f . fmap (k (iterNValue k f))
525+
526+
iterNValueByDiscardWith
527+
:: MonadDataContext f m
528+
=> r
529+
-> (NValue' t f m r -> r)
530+
-> Free (NValue' t f m) t
523531
-> r
524-
iterNValue k f = iter f . fmap (\t -> k t $ iterNValue k f)
532+
iterNValueByDiscardWith dflt = iterNValue (\ _ _ -> dflt)
525533

526534

527-
-- | @iter@ for monadic values
535+
-- | HOF of @iterM@ from @Free@
528536
iterNValueM
529537
:: (MonadDataContext f m, Monad n)
530538
=> (forall x . n x -> m x)

src/Nix/XML.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import Text.XML.Light ( Element(Element)
1717
)
1818

1919
toXML :: forall t f m . MonadDataContext f m => NValue t f m -> NixString
20-
toXML = runWithStringContext . fmap pp . iterNValue (\_ _ -> cyc) phi
20+
toXML = runWithStringContext . fmap pp . iterNValueByDiscardWith cyc phi
2121
where
2222
cyc = pure $ mkEVal "string" "<expr>"
2323

0 commit comments

Comments
 (0)