Merge pull request #356 from pikajude/mapattrs-2

Make mapAttrs take both arguments
This commit is contained in:
John Wiegley 2018-09-04 22:22:36 -07:00 committed by GitHub
commit a7afc5b2da
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 8 deletions

View file

@ -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)

View file

@ -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";
})
|]