From c0a483632c3e0193678dd58c994528d88d42ea00 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 13 Aug 2012 14:19:31 -0400 Subject: [PATCH] =?UTF-8?q?Eliminate=20some=20calls=20to=20=E2=80=98tail?= =?UTF-8?q?=E2=80=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkgs/lib/lists.nix | 4 ++-- pkgs/lib/modules.nix | 4 ++-- pkgs/lib/options.nix | 8 ++++---- pkgs/lib/strings.nix | 6 +++--- pkgs/lib/types.nix | 2 +- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/pkgs/lib/lists.nix b/pkgs/lib/lists.nix index dcb89aeec141..f5845c32ee9c 100644 --- a/pkgs/lib/lists.nix +++ b/pkgs/lib/lists.nix @@ -169,11 +169,11 @@ rec { # order. The implementation does a quick-sort. sort = strictLess: list: let - # This implementation only have one element lists on the left hand + # This implementation only has one element list on the left hand # side of the concatenation operator. qs = l: concat: if l == [] then concat - else if tail l == [] then l ++ concat + else if length l == 1 then l ++ concat else let part = partition (strictLess (head l)) (tail l); in diff --git a/pkgs/lib/modules.nix b/pkgs/lib/modules.nix index eb528f141fe2..13be0daa2877 100644 --- a/pkgs/lib/modules.nix +++ b/pkgs/lib/modules.nix @@ -2,7 +2,7 @@ let lib = import ./default.nix; in -with { inherit (builtins) head tail; }; +with { inherit (builtins) head; }; with import ./trivial.nix; with import ./lists.nix; with import ./misc.nix; @@ -64,7 +64,7 @@ rec { config = getConfig; } // ( if getImportedSets != [] then - assert tail getImportedSets == []; + assert length getImportedSets == 1; { options = head getImportedSets; } else {} diff --git a/pkgs/lib/options.nix b/pkgs/lib/options.nix index cd60b8f3b88c..05c9c5f9c0f5 100644 --- a/pkgs/lib/options.nix +++ b/pkgs/lib/options.nix @@ -2,7 +2,7 @@ let lib = import ./default.nix; in -with { inherit (builtins) head tail; }; +with { inherit (builtins) head length; }; with import ./trivial.nix; with import ./lists.nix; with import ./misc.nix; @@ -133,7 +133,7 @@ rec { # separate the merge & apply fields from the interface. mergeOptionDecls = opts: if opts == [] then {} - else if tail opts == [] then + else if length opts == 1 then let opt = head opts; in if opt ? options then opt // { options = toList opt.options; } @@ -189,7 +189,7 @@ rec { ) (attrNames defs)); mergeDefaultOption = list: - if list != [] && tail list == [] then head list + if length list == 1 then head list else if all builtins.isFunction list then x: mergeDefaultOption (map (f: f x) list) else if all isList list then concatLists list else if all isAttrs list then fold lib.mergeAttrs {} list @@ -214,7 +214,7 @@ rec { mergeOneOption = list: if list == [] then abort "This case should never happen." - else if tail list != [] then throw "Multiple definitions. Only one is allowed for this option." + else if length list != 1 then throw "Multiple definitions. Only one is allowed for this option." else head list; diff --git a/pkgs/lib/strings.nix b/pkgs/lib/strings.nix index 071bb2c995b3..fb2752d97c19 100644 --- a/pkgs/lib/strings.nix +++ b/pkgs/lib/strings.nix @@ -2,12 +2,12 @@ let lib = import ./default.nix; -inherit (builtins) add sub lessThan; +inherit (builtins) add sub lessThan length; in rec { - inherit (builtins) stringLength substring head tail lessThan sub; + inherit (builtins) stringLength substring head tail; # Concatenate a list of strings. @@ -22,7 +22,7 @@ rec { # Place an element between each element of a list, e.g., # `intersperse "," ["a" "b" "c"]' returns ["a" "," "b" "," "c"]. intersperse = separator: list: - if list == [] || tail list == [] + if list == [] || length list == 1 then list else [(head list) separator] ++ (intersperse separator (tail list)); diff --git a/pkgs/lib/types.nix b/pkgs/lib/types.nix index 956368138aa2..38ae7b43630a 100644 --- a/pkgs/lib/types.nix +++ b/pkgs/lib/types.nix @@ -157,7 +157,7 @@ rec { uniq = elemType: mkOptionType { inherit (elemType) name check iter fold docPath hasOptions; merge = list: - if tail list == [] then + if length list == 1 then head list else throw "Multiple definitions. Only one is allowed for this option.";