Skip to content

How to merge unkeyed attrs? #3208

Open
Open
@jfly

Description

@jfly

I'm curious how to merge multiple listToUnkeyedAttrs. For example:

./ $ nix repl github:nix-community/nixvim
...
nix-repl> builtins.trace (lib.nixvim.toLuaObject ((lib.nixvim.listToUnkeyedAttrs ["a" "b"]) // (lib.nixvim.listToUnkeyedAttrs ["c" "d"]) // {foo = "bar";})) null
trace: { "c", "d", foo = "bar" }
null

Ideally, I would want the resulting lua table to be:

{ "a", "b", "c", "d", foo = "bar" }

It feels like this is a fundamental issue with how listToUnkeyedAttrs represents unkeyed attrs:

./ $ nix repl github:nix-community/nixvim
nix-repl> lib.nixvim.listToUnkeyedAttrs ["a" "b"]
{
  __unkeyed-0 = "a";
  __unkeyed-1 = "b";
}

Have we considered one of the following?

  • Reworking lib.nixvim.listToUnkeyedAttrs to represent unkeyed attrs in a different way? For example, rather than injecting integer indices into the keys, we could inject the value.
  • Create a custom merge function that knows to treat these --unkeyed-<N> attrs specially.

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requestedtech debtRelated to technical debt and/or refactoring

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions