Merge pull request #356 from pikajude/mapattrs-2
Make mapAttrs take both arguments
This commit is contained in:
commit
a7afc5b2da
|
@ -70,7 +70,7 @@ import qualified Data.Text.Lazy as LazyText
|
|||
import qualified Data.Text.Lazy.Builder as Builder
|
||||
import Data.These (fromThese)
|
||||
import qualified Data.Time.Clock.POSIX as Time
|
||||
import Data.Traversable (mapM)
|
||||
import Data.Traversable (for, mapM)
|
||||
import Nix.Atoms
|
||||
import Nix.Convert
|
||||
import Nix.Effects
|
||||
|
@ -580,9 +580,10 @@ mapAttrs_ :: forall e m. MonadNix e m
|
|||
mapAttrs_ fun xs = fun >>= \f ->
|
||||
fromValue @(AttrSet (NThunk m)) xs >>= \aset -> do
|
||||
let pairs = M.toList aset
|
||||
values <- traverse (thunk . withFrame Debug
|
||||
(ErrorCall "While applying f in mapAttrs:\n")
|
||||
. (f `callFunc`) . force') (map snd pairs)
|
||||
values <- for pairs $ \(key, value) ->
|
||||
thunk $
|
||||
withFrame Debug (ErrorCall "While applying f in mapAttrs:\n") $
|
||||
callFunc ?? force' value =<< callFunc f (pure (nvStr key mempty))
|
||||
toNix . M.fromList . zip (map fst pairs) $ values
|
||||
|
||||
filter_ :: forall e m. MonadNix e m => m (NValue m) -> m (NValue m) -> m (NValue m)
|
||||
|
|
|
@ -342,10 +342,10 @@ case_rec_path_attr =
|
|||
"let src = 10; x = rec { passthru.src = src; }; in x.passthru.src"
|
||||
|
||||
case_mapattrs_builtin =
|
||||
constantEqualText' "{ a = 6; b = 7; }" [i|
|
||||
(builtins.mapAttrs (x: x+5) {
|
||||
a = 1;
|
||||
b = 2;
|
||||
constantEqualText' "{ a = \"afoo\"; b = \"bbar\"; }" [i|
|
||||
(builtins.mapAttrs (x: y: x + y) {
|
||||
a = "foo";
|
||||
b = "bar";
|
||||
})
|
||||
|]
|
||||
|
||||
|
|
Loading…
Reference in a new issue