mkArray
lib.gvariant.mkArray
Docs pulled from | This Revision | 26 minutes ago
Nixpkgs manual
Returns the GVariant array from the given type of the elements and a Nix list.
Inputs
elems-
1. Function argument
Type
mkArray :: [Any] -> GVariant
Examples
lib.gvariant.mkArray usage example
# Creating a string array
lib.gvariant.mkArray [ "a" "b" "c" ]
Noogle detected
Implementation
The following is the current implementation of this function.
mkArray =
elems:
let
vs = map mkValue (
if elems == [ ] then throw "Please create empty array with mkEmptyArray." else elems
);
firstType = (head vs).type;
elemType =
if lib.any (v: v.type != firstType) vs then
throw "Elements in a list should have same type."
else
firstType;
in
mkPrimitive (type.arrayOf elemType) vs
// {
__toString = self: "@${self.type} [${concatMapStringsSep "," toString self.value}]";
};