From 6408a6a6fd7886a55dd681e0875c79a84516c8f3 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 8 Jun 2009 22:42:42 +0000 Subject: [PATCH] * Trivial function to create a singleton list. Can reduce unnecessary indentation in expressions like environent.extraJobs = [ { name = "foo"; job = '' bla bla ''; } ]; which becomes environent.extraJobs = singleton { name = "foo"; job = '' bla bla ''; }; svn path=/nixpkgs/trunk/; revision=15892 --- pkgs/lib/lists.nix | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pkgs/lib/lists.nix b/pkgs/lib/lists.nix index b186e97a55b..8ac93476a53 100644 --- a/pkgs/lib/lists.nix +++ b/pkgs/lib/lists.nix @@ -4,6 +4,12 @@ rec { inherit (builtins) head tail isList; + # Create a list consisting of a single element. `singleton x' is + # sometimes more convenient with respect to indentation than `[x]' + # when x spans multiple lines. + singleton = x: [x]; + + # "Fold" a binary function `op' between successive elements of # `list' with `nul' as the starting value, i.e., `fold op nul [x_1 # x_2 ... x_n] == op x_1 (op x_2 ... (op x_n nul))'. (This is