mkArray
lib.gvariant.mkArray
Docs pulled from | This Revision | 10 minutes ago
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 (lib.throwIf (elems == [ ]) "Please create empty array with mkEmptyArray." elems);
elemType = lib.throwIfNot (lib.all (t: (head vs).type == t) (
map (v: v.type) vs
)) "Elements in a list should have same type." (head vs).type;
in
mkPrimitive (type.arrayOf elemType) vs
// {
__toString = self: "@${self.type} [${concatMapStringsSep "," toString self.value}]";
};