24 lines
611 B
Nix
24 lines
611 B
Nix
|
{
|
||
|
inputs,
|
||
|
cell,
|
||
|
}: let
|
||
|
brand-ctor = name:
|
||
|
assert builtins.isString name;
|
||
|
v: {
|
||
|
__brand = name;
|
||
|
__value = v;
|
||
|
};
|
||
|
unbranded_name = "__unbranded__";
|
||
|
unbranded_t = brand-ctor unbranded_name;
|
||
|
brand-of = {
|
||
|
__brand ? unbranded_name,
|
||
|
__value ? null,
|
||
|
}:
|
||
|
__brand;
|
||
|
brand-coalesce = v: if v ? __brand then v else unbranded_t v;
|
||
|
in {
|
||
|
inherit brand-ctor brand-of brand-coalesce unbranded_name;
|
||
|
brand-group = seq: builtins.mapAttrs (_: builtins.map (v: v.__value)) (builtins.groupBy (brnd: brnd.__brand) seq);
|
||
|
brand-coalesce-seq = builtins.map brand-coalesce;
|
||
|
}
|