divnix / dmerge Goto Github PK
View Code? Open in Web Editor NEWA mini merge DSL for data overlays
License: MIT License
A mini merge DSL for data overlays
License: MIT License
rhs' = dm.decorate rhs { path.to.list = dm.append;};
Defining new keys works as expected if you don't use merge functions in the RHS:
merge {} {
new = [];
nested.new = [];
}
{
"nested": {
"new": []
},
"new": []
}
But if you use a merge function it fails:
merge {} {
new = append [];
}
error: evaluation aborted with the following error message: '
a fresh right-hand-side cannot be an array merge function
at 'new':
- rhs: lambda @ …
Ok, understandable. Unexpectedly it works if the new key is nested, although the result is the append
lambda itself. This is probably not what the user wants:
merge {} {
nested.new = append [];
}
{ nested = { new = <LAMBDA>; }; }
This seem inconsistent. Defining a new key with a merge function in the RHS should either always fail with a helpful message or always succeed.
I tend to prefer the latter because that would be consistent with the behavior we observe if no merge functions are used in the RHS (see first snippet).
The UX benefit would be that it always just works™.
One drawback could be that you can make less guarantees about the outcome from looking at the LHS. However, we can already not make any guarantees about which new keys will exist in the result since that depends on whether the new keys in the RHS use merge functions or not, and whether they are nested or not, which the LHS does not know. But the benefits of the data spine would still hold if data-merge accepted both scenarios in the RHS.
The real life problem is that you may not always know which keys exist in the LHS if you get it from elsewhere, like when writing a library. Currently it is necessary to pre-create the new keys in the LHS first to allow merging in possibly new keys with merge functions from the RHS (runnable example):
{
inputs.data-merge.url = "github:divnix/data-merge";
outputs = { nixpkgs, data-merge, ... }: {
result = with data-merge; let
lhs = {}; # we may not know this value
rhs = { new = append []; };
# defeats the purpose of data-merge
prepopulatedLhs = nixpkgs.lib.recursiveUpdate lhs {
new = lhs.new or [];
};
in merge prepopulatedLhs rhs; # ok
# in merge lhs rhs; # fails
};
}
nix-repl> dm = inputs.data-merge
nix-repl> dm.merge { a = [ 6 ]; } { a = dm.update [ 0 ] [ 7 ]; }
{ a = [ ... ]; }
nix-repl> (dm.merge { a = [ 6 ]; } { a = dm.update [ 0 ] [ 7 ]; }).a
[ { ... } ]
The first item in that list should be 7.
cc @blaggacao this is resulting in syntax errors in nomad jobs built in cardano-world.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.